[llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Aug 2 17:59:23 PDT 2005
Changes in directory llvm/lib/Transforms/Utils:
SimplifyCFG.cpp updated: 1.80 -> 1.81
---
Log message:
Finally, add the required constraint checks to fix Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
the right way
---
Diffs of the changes: (+29 -2)
SimplifyCFG.cpp | 31 +++++++++++++++++++++++++++++--
1 files changed, 29 insertions(+), 2 deletions(-)
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.80 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.81
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.80 Tue Aug 2 19:38:27 2005
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:59:12 2005
@@ -98,8 +98,35 @@
}
}
}
-
- return true;
+
+ // Finally, if BB has PHI nodes that are used by things other than the PHIs in
+ // Succ and Succ has predecessors that are not Succ and not Pred, we cannot
+ // fold these blocks, as we don't know whether BB dominates Succ or not to
+ // update the PHI nodes correctly.
+ if (!isa<PHINode>(BB->begin()) || Succ->getSinglePredecessor()) return true;
+
+ // If the predecessors of Succ are only BB and Succ itself, we can handle this.
+ bool IsSafe = true;
+ for (pred_iterator PI = pred_begin(Succ), E = pred_end(Succ); PI != E; ++PI)
+ if (*PI != Succ && *PI != BB) {
+ IsSafe = false;
+ break;
+ }
+ if (IsSafe) return true;
+
+ // If the PHI nodes in BB are only used by instructions in Succ, we are ok.
+ IsSafe = true;
+ for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I) && IsSafe; ++I) {
+ PHINode *PN = cast<PHINode>(I);
+ for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); UI != E;
+ ++UI)
+ if (cast<Instruction>(*UI)->getParent() != Succ) {
+ IsSafe = false;
+ break;
+ }
+ }
+
+ return IsSafe;
}
/// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional
More information about the llvm-commits
mailing list