[PATCH] D29618: Avoid skipping instructions in IndVarSimplify::sinkUnusedInvariants
Roman Morylev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 6 19:35:49 PST 2017
rmorylev created this revision.
Fix a bug when every second instruction wasn't sinked because the iterator was incremented over it
Repository:
rL LLVM
https://reviews.llvm.org/D29618
Files:
lib/Transforms/Scalar/IndVarSimplify.cpp
test/Transforms/IndVarSimplify/exit_value_test3.ll
test/Transforms/IndVarSimplify/loop_evaluate_1.ll
test/Transforms/IndVarSimplify/sink-all.ll
Index: test/Transforms/IndVarSimplify/sink-all.ll
===================================================================
--- /dev/null
+++ test/Transforms/IndVarSimplify/sink-all.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+
+declare i1 @cond()
+
+define i32 @foo(i32 %x) nounwind {
+entry:
+ %a = mul i32 %x, 2
+ %b = mul i32 %x, 4
+ %c = mul i32 %x, 8
+ br label %for.body
+
+for.body:
+ %cmp = call i1 @cond()
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ %d = add i32 %a, %b
+ %e = add i32 %c, %d
+ ret i32 %e
+}
+
+; CHECK: for.end:
+; CHECK: mul
+; CHECK: mul
+; CHECK: mul
+; CHECK: add
+; CHECK: add
+; CHECK: ret
Index: test/Transforms/IndVarSimplify/loop_evaluate_1.ll
===================================================================
--- test/Transforms/IndVarSimplify/loop_evaluate_1.ll
+++ test/Transforms/IndVarSimplify/loop_evaluate_1.ll
@@ -26,7 +26,7 @@
; CHECK: [[VAR1:%.+]] = add i32 %arg, -11
; CHECK: [[VAR2:%.+]] = lshr i32 [[VAR1]], 1
; CHECK: [[VAR3:%.+]] = add i32 [[VAR2]], 1
-; CHECK: [[VAR4:%.+]] = phi i32 [ 0, %bb ], [ [[VAR3]], %bb1.preheader ]
+; CHECK: [[VAR4:%.+]] = phi i32 [ 0, %bb ], [ [[VAR3]], %bb7.loopexit ]
; CHECK: ret i32 [[VAR4]]
define i32 @test2(i32 %arg) {
bb:
Index: test/Transforms/IndVarSimplify/exit_value_test3.ll
===================================================================
--- test/Transforms/IndVarSimplify/exit_value_test3.ll
+++ test/Transforms/IndVarSimplify/exit_value_test3.ll
@@ -4,8 +4,9 @@
; is high because the loop can be deleted after the exit value rewrite.
;
; CHECK-LABEL: @_Z3fooPKcjj(
+; CHECK: br label %[[LABEL:[a-zA-Z0-9_.]+]]
+; CHECK: [[LABEL]]:
; CHECK: udiv
-; CHECK: [[LABEL:^[a-zA-Z0-9_.]+]]:
; CHECK-NOT: br {{.*}} [[LABEL]]
define i32 @_Z3fooPKcjj(i8* nocapture readnone %s, i32 %len, i32 %c) #0 {
Index: lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- lib/Transforms/Scalar/IndVarSimplify.cpp
+++ lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2356,6 +2356,7 @@
ToMove->moveBefore(*ExitBlock, InsertPt);
if (Done) break;
InsertPt = ToMove->getIterator();
+ ++I; // Do not skip instructions
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29618.87357.patch
Type: text/x-patch
Size: 2237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170207/d0c4c49f/attachment.bin>
More information about the llvm-commits
mailing list