summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYi Jiang <yjiang@apple.com>2014-10-29 20:19:47 +0000
committerYi Jiang <yjiang@apple.com>2014-10-29 20:19:47 +0000
commitab19fff4d8f9c8a4949b0652b5f9f31d757e0ae3 (patch)
tree89babc0ff4c844132a7ddcecbc8dd6241b779d39
parent2ec8e1bd20d01102a5e5a5560d4542030ef83056 (diff)
downloadbcm5719-llvm-ab19fff4d8f9c8a4949b0652b5f9f31d757e0ae3.tar.gz
bcm5719-llvm-ab19fff4d8f9c8a4949b0652b5f9f31d757e0ae3.zip
Do not simplifyLatch for loops where hoisting increments couldresult in extra live range interferance
llvm-svn: 220872
-rw-r--r--llvm/lib/Transforms/Scalar/LoopRotation.cpp33
-rw-r--r--llvm/test/Transforms/LoopRotate/dbgvalue.ll6
-rw-r--r--llvm/test/Transforms/LoopRotate/simplifylatch.ll2
3 files changed, 34 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
index ddb53926ff7..afd2eca598e 100644
--- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
@@ -194,8 +194,13 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
/// heuristics. We handle a single arithmetic instruction along with any type
/// conversions.
static bool shouldSpeculateInstrs(BasicBlock::iterator Begin,
- BasicBlock::iterator End) {
+ BasicBlock::iterator End, Loop *L) {
bool seenIncrement = false;
+ bool MultiExitLoop = false;
+
+ if (!L->getExitingBlock())
+ MultiExitLoop = true;
+
for (BasicBlock::iterator I = Begin; I != End; ++I) {
if (!isSafeToSpeculativelyExecute(I))
@@ -219,11 +224,33 @@ static bool shouldSpeculateInstrs(BasicBlock::iterator Begin,
case Instruction::Xor:
case Instruction::Shl:
case Instruction::LShr:
- case Instruction::AShr:
+ case Instruction::AShr: {
+ Value *IVOpnd = nullptr;
+ if (isa<ConstantInt>(I->getOperand(0)))
+ IVOpnd = I->getOperand(1);
+
+ if (isa<ConstantInt>(I->getOperand(1))) {
+ if (IVOpnd)
+ return false;
+
+ IVOpnd = I->getOperand(0);
+ }
+
+ // If increment operand is used outside of the loop, this speculation
+ // could cause extra live range interference.
+ if (MultiExitLoop && IVOpnd) {
+ for (User *UseI : IVOpnd->users()) {
+ auto *UserInst = cast<Instruction>(UseI);
+ if (!L->contains(UserInst))
+ return false;
+ }
+ }
+
if (seenIncrement)
return false;
seenIncrement = true;
break;
+ }
case Instruction::Trunc:
case Instruction::ZExt:
case Instruction::SExt:
@@ -259,7 +286,7 @@ bool LoopRotate::simplifyLoopLatch(Loop *L) {
if (!BI)
return false;
- if (!shouldSpeculateInstrs(Latch->begin(), Jmp))
+ if (!shouldSpeculateInstrs(Latch->begin(), Jmp, L))
return false;
DEBUG(dbgs() << "Folding loop latch " << Latch->getName() << " into "
diff --git a/llvm/test/Transforms/LoopRotate/dbgvalue.ll b/llvm/test/Transforms/LoopRotate/dbgvalue.ll
index e90065609aa..4da0776d6c8 100644
--- a/llvm/test/Transforms/LoopRotate/dbgvalue.ll
+++ b/llvm/test/Transforms/LoopRotate/dbgvalue.ll
@@ -46,9 +46,9 @@ define void @FindFreeHorzSeg(i64 %startCol, i64 %row, i64* %rowStart) {
; CHECK-LABEL: define void @FindFreeHorzSeg(
; CHECK: %dec = add
; CHECK-NEXT: tail call void @llvm.dbg.value
-; CHECK-NEXT: br i1 %tobool, label %for.cond, label %[[LOOP_EXIT:[^,]*]]
-; CHECK: [[LOOP_EXIT]]:
-; CHECK-NEXT: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ]
+; CHECK: %cmp = icmp
+; CHECK: br i1 %cmp
+; CHECK: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ]
; CHECK-NEXT: br label %for.end
diff --git a/llvm/test/Transforms/LoopRotate/simplifylatch.ll b/llvm/test/Transforms/LoopRotate/simplifylatch.ll
index d646cb9d6cb..62e5b1ae11d 100644
--- a/llvm/test/Transforms/LoopRotate/simplifylatch.ll
+++ b/llvm/test/Transforms/LoopRotate/simplifylatch.ll
@@ -4,7 +4,7 @@
@mode_table = global [4 x i32] zeroinitializer ; <[4 x i32]*> [#uses=1]
; CHECK-LABEL: @f(
-; CHECK-NOT: bb4
+; CHECK-NOT: bb:
define i8 @f() {
entry:
tail call i32 @fegetround( ) ; <i32>:0 [#uses=1]
OpenPOWER on IntegriCloud