summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-12-15 00:55:35 +0000
committerOwen Anderson <resistor@mac.com>2010-12-15 00:55:35 +0000
commit35609d97ae89b8e13f40f4e6b9b056954f8baa83 (patch)
treef2725d424c81f54aca65c93e84fe943261a212e2 /llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
parent15c85c916fafb454be24d30ed5a6cec18d0ea89c (diff)
downloadbcm5719-llvm-35609d97ae89b8e13f40f4e6b9b056954f8baa83.tar.gz
bcm5719-llvm-35609d97ae89b8e13f40f4e6b9b056954f8baa83.zip
Fix PR8790, another instance where unreachable code can cause instruction simplification to fail,
this case involve a select that simplifies to itself. llvm-svn: 121817
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index f364375ebd2..be12973b645 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -73,7 +73,12 @@ bool CorrelatedValuePropagation::processSelect(SelectInst *S) {
ConstantInt *CI = dyn_cast<ConstantInt>(C);
if (!CI) return false;
- S->replaceAllUsesWith(S->getOperand(CI->isOne() ? 1 : 2));
+ Value *ReplaceWith = S->getOperand(1);
+ Value *Other = S->getOperand(2);
+ if (!CI->isOne()) std::swap(ReplaceWith, Other);
+ if (ReplaceWith == S) ReplaceWith = UndefValue::get(S->getType());
+
+ S->replaceAllUsesWith(ReplaceWith);
S->eraseFromParent();
++NumSelects;
OpenPOWER on IntegriCloud