[llvm] 03bc311 - [CorrelatedValuePropagation] Remove redundant if statement in processSelect()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 28 10:01:28 PDT 2020
Author: Enna1
Date: 2020-03-28T18:01:17+01:00
New Revision: 03bc311a16e292025f150ddafa9d468af562b897
URL: https://github.com/llvm/llvm-project/commit/03bc311a16e292025f150ddafa9d468af562b897
DIFF: https://github.com/llvm/llvm-project/commit/03bc311a16e292025f150ddafa9d468af562b897.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Removed:
################################################################################
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<Constant>(S->getOperand(0))) return false;
+ if (isa<Constant>(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<ConstantInt>(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();
More information about the llvm-commits
mailing list