aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2010-05-03 18:06:58 +0000
committerDevang Patel <dpatel@apple.com>2010-05-03 18:06:58 +0000
commit86b6f80a4cbae79688723dd24824ff0609349da1 (patch)
treeabc52e6eecb708cac2c013a7b58e853a004fe212
parent34c3e36e6317b0ed448ccd2c567d5b088275fd7d (diff)
Check for side effects before splitting loop.
Patch by Jakub Staszak! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102928 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp19
-rw-r--r--test/Transforms/LoopIndexSplit/PR4174-2.ll38
-rw-r--r--test/Transforms/LoopIndexSplit/PR4174.ll23
3 files changed, 80 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 16d3f2f703..101ff5b200 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -948,6 +948,25 @@ bool LoopIndexSplit::splitLoop() {
if (!IVBasedValues.count(SplitCondition->getOperand(!SVOpNum)))
return false;
+ // Check for side effects.
+ for (Loop::block_iterator I = L->block_begin(), E = L->block_end();
+ I != E; ++I) {
+ BasicBlock *BB = *I;
+
+ assert(DT->dominates(Header, BB));
+ if (DT->properlyDominates(SplitCondition->getParent(), BB))
+ continue;
+
+ for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
+ BI != BE; ++BI) {
+ Instruction *Inst = BI;
+
+ if (!Inst->isSafeToSpeculativelyExecute() && !isa<PHINode>(Inst)
+ && !isa<BranchInst>(Inst) && !isa<DbgInfoIntrinsic>(Inst))
+ return false;
+ }
+ }
+
// Normalize loop conditions so that it is easier to calculate new loop
// bounds.
if (IVisGT(*ExitCondition) || IVisGE(*ExitCondition)) {
diff --git a/test/Transforms/LoopIndexSplit/PR4174-2.ll b/test/Transforms/LoopIndexSplit/PR4174-2.ll
new file mode 100644
index 0000000000..cc17bc0a93
--- /dev/null
+++ b/test/Transforms/LoopIndexSplit/PR4174-2.ll
@@ -0,0 +1,38 @@
+; RUN: llvm-as < %s | opt -loop-index-split | llvm-dis | not grep clone
+
+declare void @f()
+
+define fastcc i32 @main() nounwind {
+entry:
+ br label %bb1552
+
+bb1552:
+ %j295.0.reg2mem.0 = phi i32 [ %storemerge110, %bb1669 ], [ 0, %entry ]
+ br label %bb1553
+
+bb1553:
+ call void @f()
+ %tmp1628 = icmp sgt i32 %j295.0.reg2mem.0, -3
+ br i1 %tmp1628, label %bb1588, label %bb1616
+
+bb1588:
+ br label %bb1616
+
+bb1616:
+ %tmp1629 = icmp sgt i32 %j295.0.reg2mem.0, -3
+ br i1 %tmp1629, label %bb1649, label %bb1632
+
+bb1632:
+ br label %bb1669
+
+bb1649:
+ br label %bb1669
+
+bb1669:
+ %storemerge110 = add i32 %j295.0.reg2mem.0, 1
+ %tmp1672 = icmp sgt i32 %storemerge110, 3
+ br i1 %tmp1672, label %bb1678, label %bb1552
+
+bb1678:
+ ret i32 0
+}
diff --git a/test/Transforms/LoopIndexSplit/PR4174.ll b/test/Transforms/LoopIndexSplit/PR4174.ll
new file mode 100644
index 0000000000..e8f5a737f0
--- /dev/null
+++ b/test/Transforms/LoopIndexSplit/PR4174.ll
@@ -0,0 +1,23 @@
+; RUN: llvm-as < %s | opt -loop-index-split | llvm-dis | not grep clone
+
+declare void @f()
+
+define i32 @main() {
+entry:
+ br label %head
+head:
+ %i = phi i32 [0, %entry], [%i1, %tail]
+ call void @f()
+ %splitcond = icmp slt i32 %i, 2
+ br i1 %splitcond, label %yes, label %no
+yes:
+ br label %tail
+no:
+ br label %tail
+tail:
+ %i1 = add i32 %i, 1
+ %exitcond = icmp slt i32 %i1, 4
+ br i1 %exitcond, label %head, label %exit
+exit:
+ ret i32 0
+}