diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 4d9883dd662e..7c2ddf2947d2 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -125,7 +125,7 @@ Pass *llvm::createCorrelatedValuePropagationPass() { static bool processSelect(SelectInst *S, LazyValueInfo *LVI) { if (S->getType()->isVectorTy()) return false; - if (isa(S->getOperand(0))) return false; + if (isa(S->getCondition())) return false; Constant *C = LVI->getConstant(S->getCondition(), S->getParent(), S); if (!C) return false; @@ -133,11 +133,7 @@ static bool processSelect(SelectInst *S, LazyValueInfo *LVI) { ConstantInt *CI = dyn_cast(C); if (!CI) return false; - Value *ReplaceWith = S->getTrueValue(); - Value *Other = S->getFalseValue(); - if (!CI->isOne()) std::swap(ReplaceWith, Other); - if (ReplaceWith == S) ReplaceWith = UndefValue::get(S->getType()); - + Value *ReplaceWith = CI->isOne() ? S->getTrueValue() : S->getFalseValue(); S->replaceAllUsesWith(ReplaceWith); S->eraseFromParent();