diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -125,7 +125,7 @@ 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 @@ 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();