[llvm] r220872 - Do not simplifyLatch for loops where hoisting increments couldresult in extra live range interferance

Patrik Hägglund H patrik.h.hagglund at ericsson.com
Mon Dec 8 05:37:12 PST 2014


> +          auto *UserInst = cast<Instruction>(UseI);

A 'User' may either be an 'Instruction' or  a 'Constant'. Therefore, this line may result in an assert if 'UseI' is a 'Constant'. I have started to see this problem in our internal tests. I'm not familiar with this kind of code, and is not sure if a constant experssion should be ignored or handled similar to an instruction. As a workaround in my tree, I currently ignore the 'Constant' case:

+          auto *UserInst = dyn_cast<Instruction>(UseI);
+          if (UserInst == nullptr)
+            continue;

/Patrik Hägglund

-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Yi Jiang
Sent: den 29 oktober 2014 21:20
To: llvm-commits at cs.uiuc.edu
Subject: [llvm] r220872 - Do not simplifyLatch for loops where hoisting increments couldresult in extra live range interferance

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]


_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list