[llvm] r220872 - Do not simplifyLatch for loops where hoisting increments couldresult in extra live range interferance
Yi Jiang
yjiang at apple.com
Wed Oct 29 13:19:47 PDT 2014
Author: yjiang
Date: Wed Oct 29 15:19:47 2014
New Revision: 220872
URL: http://llvm.org/viewvc/llvm-project?rev=220872&view=rev
Log:
Do not simplifyLatch for loops where hoisting increments couldresult in extra live range interferance
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
llvm/trunk/test/Transforms/LoopRotate/dbgvalue.ll
llvm/trunk/test/Transforms/LoopRotate/simplifylatch.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=220872&r1=220871&r2=220872&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Wed Oct 29 15:19:47 2014
@@ -194,8 +194,13 @@ static void RewriteUsesOfClonedInstructi
/// 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(BasicB
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
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 "
Modified: llvm/trunk/test/Transforms/LoopRotate/dbgvalue.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/dbgvalue.ll?rev=220872&r1=220871&r2=220872&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/dbgvalue.ll (original)
+++ llvm/trunk/test/Transforms/LoopRotate/dbgvalue.ll Wed Oct 29 15:19:47 2014
@@ -46,9 +46,9 @@ define void @FindFreeHorzSeg(i64 %startC
; 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
Modified: llvm/trunk/test/Transforms/LoopRotate/simplifylatch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/simplifylatch.ll?rev=220872&r1=220871&r2=220872&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/simplifylatch.ll (original)
+++ llvm/trunk/test/Transforms/LoopRotate/simplifylatch.ll Wed Oct 29 15:19:47 2014
@@ -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]
More information about the llvm-commits
mailing list