summaryrefslogtreecommitdiff
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-11-15 17:52:45 +0000
committerDuncan Sands <baldrick@free.fr>2010-11-15 17:52:45 +0000
commit552008946530e01efdad15044e1f621883d14a3a (patch)
treef03a042355f51a15a352a2872e313f399573f336 /lib/Analysis/InstructionSimplify.cpp
parent503dcc982227893c532f03cbd6449e01a1739df3 (diff)
downloadllvm-552008946530e01efdad15044e1f621883d14a3a.tar.gz
llvm-552008946530e01efdad15044e1f621883d14a3a.tar.bz2
llvm-552008946530e01efdad15044e1f621883d14a3a.tar.xz
Teach InstructionSimplify the trick of skipping incoming phi
values that are equal to the phi itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119161 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 282e0d31be..a8288bf67a 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -142,9 +142,12 @@ static Value *ThreadBinOpOverPHI(unsigned Opcode, Value *LHS, Value *RHS,
// Evaluate the BinOp on the incoming phi values.
Value *CommonValue = 0;
for (unsigned i = 0, e = PI->getNumIncomingValues(); i != e; ++i) {
+ Value *Incoming = PI->getIncomingValue(i);
+ // If the incoming value is the phi node itself, it can be safely skipped.
+ if (Incoming == PI) continue;
Value *V = PI == LHS ?
- SimplifyBinOp(Opcode, PI->getIncomingValue(i), RHS, TD, MaxRecurse) :
- SimplifyBinOp(Opcode, LHS, PI->getIncomingValue(i), TD, MaxRecurse);
+ SimplifyBinOp(Opcode, Incoming, RHS, TD, MaxRecurse) :
+ SimplifyBinOp(Opcode, LHS, Incoming, TD, MaxRecurse);
// If the operation failed to simplify, or simplified to a different value
// to previously, then give up.
if (!V || (CommonValue && V != CommonValue))
@@ -172,8 +175,10 @@ static Value *ThreadCmpOverPHI(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
// Evaluate the BinOp on the incoming phi values.
Value *CommonValue = 0;
for (unsigned i = 0, e = PI->getNumIncomingValues(); i != e; ++i) {
- Value *V = SimplifyCmpInst(Pred, PI->getIncomingValue(i), RHS, TD,
- MaxRecurse);
+ Value *Incoming = PI->getIncomingValue(i);
+ // If the incoming value is the phi node itself, it can be safely skipped.
+ if (Incoming == PI) continue;
+ Value *V = SimplifyCmpInst(Pred, Incoming, RHS, TD, MaxRecurse);
// If the operation failed to simplify, or simplified to a different value
// to previously, then give up.
if (!V || (CommonValue && V != CommonValue))