aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2009-03-12 01:00:26 +0000
committerDale Johannesen <dalej@apple.com>2009-03-12 01:00:26 +0000
commita9537cf3fcf9fdaac94749db9fbd34912b1f0f08 (patch)
tree97fed0ea1511f7c34a540c446b6da581f5df257c /lib/Transforms/Utils/SimplifyCFG.cpp
parentfd82995823e00cb60cc8977280254de73ed9d6b7 (diff)
Fix some nondeterministic behavior when forwarding
from a switch table. Multiple table entries that branch to the same place were being sorted by the pointer value of the ConstantInt*; changed to sort by the actual value of the ConstantInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66749 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 264e4e0df4..80eab1c1f8 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -719,6 +719,16 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
return false;
}
+/// A sorting function for the std::set's in the following function which track
+/// the values in switches. This forces deterministic behavior by comparing
+/// the values rather than the pointers.
+class Sorter {
+public:
+ bool operator() (ConstantInt * const &p, ConstantInt * const &q) const {
+ return p->getSExtValue() < q->getSExtValue();
+ }
+};
+
/// FoldValueComparisonIntoPredecessors - The specified terminator is a value
/// equality comparison instruction (either a switch or a branch on "X == c").
/// See if any of the predecessors of the terminator block are value comparisons
@@ -754,7 +764,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
if (PredDefault == BB) {
// If this is the default destination from PTI, only the edges in TI
// that don't occur in PTI, or that branch to BB will be activated.
- std::set<ConstantInt*> PTIHandled;
+ std::set<ConstantInt*, Sorter> PTIHandled;
for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
if (PredCases[i].second != BB)
PTIHandled.insert(PredCases[i].first);
@@ -782,7 +792,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
// If this is not the default destination from PSI, only the edges
// in SI that occur in PSI with a destination of BB will be
// activated.
- std::set<ConstantInt*> PTIHandled;
+ std::set<ConstantInt*, Sorter> PTIHandled;
for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
if (PredCases[i].second == BB) {
PTIHandled.insert(PredCases[i].first);
@@ -803,7 +813,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
// If there are any constants vectored to BB that TI doesn't handle,
// they must go to the default destination of TI.
- for (std::set<ConstantInt*>::iterator I = PTIHandled.begin(),
+ for (std::set<ConstantInt*, Sorter>::iterator I = PTIHandled.begin(),
E = PTIHandled.end(); I != E; ++I) {
PredCases.push_back(std::make_pair(*I, BBDefault));
NewSuccessors.push_back(BBDefault);