[llvm] r243545 - [Unroll] Handle SwitchInst properly.

Michael Zolotukhin mzolotukhin at apple.com
Wed Jul 29 11:10:33 PDT 2015


Author: mzolotukhin
Date: Wed Jul 29 13:10:33 2015
New Revision: 243545

URL: http://llvm.org/viewvc/llvm-project?rev=243545&view=rev
Log:
[Unroll] Handle SwitchInst properly.

Previously successor selection was simply wrong.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
    llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=243545&r1=243544&r2=243545&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Wed Jul 29 13:10:33 2015
@@ -619,8 +619,8 @@ analyzeLoopUnrollCost(const Loop *L, uns
           if (isa<UndefValue>(SimpleCond))
             Succ = SI->getSuccessor(0);
           else
-            Succ =
-                SI->getSuccessor(cast<ConstantInt>(SimpleCond)->getSExtValue());
+            Succ = SI->findCaseValue(cast<ConstantInt>(SimpleCond))
+                       .getCaseSuccessor();
           if (L->contains(Succ))
             BBWorklist.insert(Succ);
           continue;

Modified: llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll?rev=243545&r1=243544&r2=243545&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll Wed Jul 29 13:10:33 2015
@@ -57,3 +57,27 @@ for.inc:
 for.end:                                          ; preds = %for.inc
   ret void
 }
+
+define void @switch() {
+entry:
+  br label %for.body
+
+for.body:
+  %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
+  %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
+  %x1 = load i32, i32* %arrayidx1, align 4
+  switch i32 %x1, label %l1 [
+  ]
+
+l1:
+  %x2 = add i32 %x1, 2
+  br label %for.inc
+
+for.inc:
+  %iv.1 = add nuw nsw i64 %iv.0, 1
+  %exitcond = icmp eq i64 %iv.1, 10
+  br i1 %exitcond, label %for.end, label %for.body
+
+for.end:
+  ret void
+}





More information about the llvm-commits mailing list