[llvm] r227171 - LoopRotate: Don't walk the uses of a Constant

David Majnemer david.majnemer at gmail.com
Mon Jan 26 22:21:43 PST 2015


Author: majnemer
Date: Tue Jan 27 00:21:43 2015
New Revision: 227171

URL: http://llvm.org/viewvc/llvm-project?rev=227171&view=rev
Log:
LoopRotate: Don't walk the uses of a Constant

LoopRotate wanted to avoid live range interference by looking at the
uses of a Value in the loop latch and seeing if any lied outside of the
loop.  We would wrongly perform this operation on Constants.

This fixes PR22337.

Added:
    llvm/trunk/test/Transforms/LoopRotate/pr22337.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=227171&r1=227170&r2=227171&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Tue Jan 27 00:21:43 2015
@@ -229,20 +229,17 @@ static bool shouldSpeculateInstrs(BasicB
     case Instruction::Shl:
     case Instruction::LShr:
     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);
-      }
+      Value *IVOpnd = !isa<Constant>(I->getOperand(0))
+                          ? I->getOperand(0)
+                          : !isa<Constant>(I->getOperand(1))
+                                ? I->getOperand(1)
+                                : nullptr;
+      if (!IVOpnd)
+        return false;
 
       // If increment operand is used outside of the loop, this speculation
       // could cause extra live range interference.
-      if (MultiExitLoop && IVOpnd) {
+      if (MultiExitLoop) {
         for (User *UseI : IVOpnd->users()) {
           auto *UserInst = cast<Instruction>(UseI);
           if (!L->contains(UserInst))

Added: llvm/trunk/test/Transforms/LoopRotate/pr22337.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/pr22337.ll?rev=227171&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/pr22337.ll (added)
+++ llvm/trunk/test/Transforms/LoopRotate/pr22337.ll Tue Jan 27 00:21:43 2015
@@ -0,0 +1,24 @@
+; RUN: opt < %s -loop-rotate -S | FileCheck %s
+
+ at a = external global i8, align 4
+ at tmp = global i8* @a
+
+define void @f() {
+; CHECK-LABEL: define void @f(
+; CHECK: getelementptr i8* @a, i32 0
+entry:
+  br label %for.preheader
+
+for.preheader:
+  br i1 undef, label %if.then8, label %for.body
+
+for.body:
+  br i1 undef, label %if.end, label %if.then8
+
+if.end:
+  %arrayidx = getelementptr i8* @a, i32 0
+  br label %for.preheader
+
+if.then8:
+  unreachable
+}





More information about the llvm-commits mailing list