; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -S -loop-unroll -verify-dom-info | FileCheck %s
+; RUN: opt < %s -S -loop-unroll -unroll-peel-max-count=4 -verify-dom-info | FileCheck %s
declare void @f1()
declare void @f2()
}
define void @test7(i32 %k) {
-; FIXME: Could simplify loop body by peeling one additional iteration after
-; i != 3 becomes false
; CHECK-LABEL: @test7(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
}
define void @test8(i32 %k) {
-; FIXME: Could simplify loop body by peeling one additional iteration after
-; i == 3 becomes true.
; CHECK-LABEL: @test8(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
+; NOTE: here we should only peel the first iteration,
+; i.e. all calls to sink() must stay in loop.
define void @test12__peel_first_iter_via_eq_pred(i32 %len) {
; CHECK-LABEL: @test12__peel_first_iter_via_eq_pred(
; CHECK-NEXT: entry:
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
+; NOTE: here we should only peel the first iteration,
+; i.e. all calls to sink() must stay in loop.
define void @test13__peel_first_iter_via_ne_pred(i32 %len) {
; CHECK-LABEL: @test13__peel_first_iter_via_ne_pred(
; CHECK-NEXT: entry:
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
+; No peeling is profitable here.
define void @test15__ivar_mod2_is_1(i32 %len) {
; CHECK-LABEL: @test15__ivar_mod2_is_1(
; CHECK-NEXT: entry:
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
+; No peeling is profitable here.
define void @test16__ivar_mod2_is_0(i32 %len) {
; CHECK-LABEL: @test16__ivar_mod2_is_0(
; CHECK-NEXT: entry:
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
+; Similar to @test7, we need to peel one extra iteration, and we can't do that
+; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all.
+define void @test17(i32 %k) {
+; CHECK-LABEL: @test17(
+; CHECK-NEXT: for.body.lr.ph:
+; CHECK-NEXT: br label [[FOR_BODY:%.*]]
+; CHECK: for.body:
+; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[I_05]], 4
+; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
+; CHECK: if.then:
+; CHECK-NEXT: call void @f1()
+; CHECK-NEXT: br label [[FOR_INC]]
+; CHECK: for.inc:
+; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
+; CHECK: for.end:
+; CHECK-NEXT: ret void
+;
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
+ %cmp1 = icmp ne i32 %i.05, 4
+ br i1 %cmp1, label %if.then, label %for.inc
+
+if.then:
+ call void @f1()
+ br label %for.inc
+
+for.inc:
+ %inc = add nsw i32 %i.05, 1
+ %cmp = icmp slt i32 %inc, %k
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
+
+; Similar to @test8, we need to peel one extra iteration, and we can't do that
+; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all.
+define void @test18(i32 %k) {
+; CHECK-LABEL: @test18(
+; CHECK-NEXT: for.body.lr.ph:
+; CHECK-NEXT: br label [[FOR_BODY:%.*]]
+; CHECK: for.body:
+; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
+; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[I_05]], 4
+; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
+; CHECK: if.then:
+; CHECK-NEXT: call void @f1()
+; CHECK-NEXT: br label [[FOR_INC]]
+; CHECK: for.inc:
+; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
+; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
+; CHECK: for.end:
+; CHECK-NEXT: ret void
+;
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
+ %cmp1 = icmp eq i32 %i.05, 4
+ br i1 %cmp1, label %if.then, label %for.inc
+
+if.then:
+ call void @f1()
+ br label %for.inc
+
+for.inc:
+ %inc = add nsw i32 %i.05, 1
+ %cmp = icmp slt i32 %inc, %k
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
+
declare void @init()
declare void @sink()