Skip to content

Commit 03bc311

Browse files
Enna1nikic
authored andcommitted
[CorrelatedValuePropagation] Remove redundant if statement in processSelect()
This statement if (ReplaceWith == S) ReplaceWith = UndefValue::get(S->getType()); is introduced in https://reviews.llvm.org/rG35609d97ae89b8e13f40f4e6b9b056954f8baa83 to fix a case where unreachable code can cause select instruction simplification to fail. In https://reviews.llvm.org/rGd10480657527ffb44ea213460fb3676a6b1300aa, we begin to perform a depth-first walk of basic blocks. This means we will not visit unreachable blocks. So we do not need this the special check any more. Differential Revision: https://reviews.llvm.org/D76753
1 parent e6112a5 commit 03bc311

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,15 @@ Pass *llvm::createCorrelatedValuePropagationPass() {
125125

126126
static bool processSelect(SelectInst *S, LazyValueInfo *LVI) {
127127
if (S->getType()->isVectorTy()) return false;
128-
if (isa<Constant>(S->getOperand(0))) return false;
128+
if (isa<Constant>(S->getCondition())) return false;
129129

130130
Constant *C = LVI->getConstant(S->getCondition(), S->getParent(), S);
131131
if (!C) return false;
132132

133133
ConstantInt *CI = dyn_cast<ConstantInt>(C);
134134
if (!CI) return false;
135135

136-
Value *ReplaceWith = S->getTrueValue();
137-
Value *Other = S->getFalseValue();
138-
if (!CI->isOne()) std::swap(ReplaceWith, Other);
139-
if (ReplaceWith == S) ReplaceWith = UndefValue::get(S->getType());
140-
136+
Value *ReplaceWith = CI->isOne() ? S->getTrueValue() : S->getFalseValue();
141137
S->replaceAllUsesWith(ReplaceWith);
142138
S->eraseFromParent();
143139

0 commit comments

Comments
 (0)