; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -passes=loop-unroll -unroll-peel-max-count=4 -verify-dom-info | FileCheck %s
declare void @f1()
declare void @f2()
declare void @f3(i32)
; Check that we can peel off iterations that make conditions true.
define void @test1(i32 %k) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i32 0, 2
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
; CHECK: if.else.peel:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ult i32 [[INC_PEEL]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
; CHECK: if.else.peel4:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL6:%.*]]
; CHECK: if.then.peel5:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL6]]
; CHECK: for.inc.peel6:
; CHECK-NEXT: [[INC_PEEL7:%.*]] = add nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL8:%.*]] = icmp slt i32 [[INC_PEEL7]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL8]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT9:%.*]]
; CHECK: for.body.peel.next9:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL7]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: if.else:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: for.inc:
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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 ult i32 %i.05, 2
br i1 %cmp1, label %if.then, label %if.else
if.then:
call void @f1()
br label %for.inc
if.else:
call void @f2()
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, !llvm.loop !1
for.end:
ret void
}
!1 = distinct !{!1}
; Check we peel off the maximum number of iterations that make conditions true.
define void @test2(i32 %k) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i32 0, 2
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
; CHECK: if.else.peel:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[IF2_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[IF2_PEEL]]
; CHECK: if2.peel:
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 4
; CHECK-NEXT: br i1 [[CMP2_PEEL]], label [[IF_THEN2_PEEL:%.*]], label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then2.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ult i32 [[INC_PEEL]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
; CHECK: if.else.peel4:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[IF2_PEEL6:%.*]]
; CHECK: if.then.peel5:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[IF2_PEEL6]]
; CHECK: if2.peel6:
; CHECK-NEXT: [[CMP2_PEEL7:%.*]] = icmp ult i32 [[INC_PEEL]], 4
; CHECK-NEXT: br i1 [[CMP2_PEEL7]], label [[IF_THEN2_PEEL8:%.*]], label [[FOR_INC_PEEL9:%.*]]
; CHECK: if.then2.peel8:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL9]]
; CHECK: for.inc.peel9:
; CHECK-NEXT: [[INC_PEEL10:%.*]] = add nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL11:%.*]] = icmp slt i32 [[INC_PEEL10]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL11]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL13:%.*]]
; CHECK: for.body.peel13:
; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp ult i32 [[INC_PEEL10]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL14]], label [[IF_THEN_PEEL16:%.*]], label [[IF_ELSE_PEEL15:%.*]]
; CHECK: if.else.peel15:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[IF2_PEEL17:%.*]]
; CHECK: if.then.peel16:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[IF2_PEEL17]]
; CHECK: if2.peel17:
; CHECK-NEXT: [[CMP2_PEEL18:%.*]] = icmp ult i32 [[INC_PEEL10]], 4
; CHECK-NEXT: br i1 [[CMP2_PEEL18]], label [[IF_THEN2_PEEL19:%.*]], label [[FOR_INC_PEEL20:%.*]]
; CHECK: if.then2.peel19:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL20]]
; CHECK: for.inc.peel20:
; CHECK-NEXT: [[INC_PEEL21:%.*]] = add nsw i32 [[INC_PEEL10]], 1
; CHECK-NEXT: [[CMP_PEEL22:%.*]] = icmp slt i32 [[INC_PEEL21]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL22]], label [[FOR_BODY_PEEL_NEXT12:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next12:
; CHECK-NEXT: br label [[FOR_BODY_PEEL24:%.*]]
; CHECK: for.body.peel24:
; CHECK-NEXT: [[CMP1_PEEL25:%.*]] = icmp ult i32 [[INC_PEEL21]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL25]], label [[IF_THEN_PEEL27:%.*]], label [[IF_ELSE_PEEL26:%.*]]
; CHECK: if.else.peel26:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[IF2_PEEL28:%.*]]
; CHECK: if.then.peel27:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[IF2_PEEL28]]
; CHECK: if2.peel28:
; CHECK-NEXT: [[CMP2_PEEL29:%.*]] = icmp ult i32 [[INC_PEEL21]], 4
; CHECK-NEXT: br i1 [[CMP2_PEEL29]], label [[IF_THEN2_PEEL30:%.*]], label [[FOR_INC_PEEL31:%.*]]
; CHECK: if.then2.peel30:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL31]]
; CHECK: for.inc.peel31:
; CHECK-NEXT: [[INC_PEEL32:%.*]] = add nsw i32 [[INC_PEEL21]], 1
; CHECK-NEXT: [[CMP_PEEL33:%.*]] = icmp slt i32 [[INC_PEEL32]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL33]], label [[FOR_BODY_PEEL_NEXT23:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next23:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT34:%.*]]
; CHECK: for.body.peel.next34:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL32]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[IF2:%.*]]
; CHECK: if.else:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[IF2]]
; CHECK: if2:
; CHECK-NEXT: br i1 false, label [[IF_THEN2:%.*]], label [[FOR_INC]]
; CHECK: if.then2:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: for.inc:
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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 ult i32 %i.05, 2
br i1 %cmp1, label %if.then, label %if.else
if.then:
call void @f1()
br label %if2
if.else:
call void @f2()
br label %if2
if2:
%cmp2 = icmp ult i32 %i.05, 4
br i1 %cmp2, label %if.then2, label %for.inc
if.then2:
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, !llvm.loop !2
for.end:
ret void
}
!2 = distinct !{!2}
; Check that we can peel off iterations that make a condition false.
define void @test3(i32 %k) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ugt i32 0, 2
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
; CHECK: if.else.peel:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ugt i32 [[INC_PEEL]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
; CHECK: if.else.peel4:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL6:%.*]]
; CHECK: if.then.peel5:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL6]]
; CHECK: for.inc.peel6:
; CHECK-NEXT: [[INC_PEEL7:%.*]] = add nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL8:%.*]] = icmp slt i32 [[INC_PEEL7]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL8]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL10:%.*]]
; CHECK: for.body.peel10:
; CHECK-NEXT: [[CMP1_PEEL11:%.*]] = icmp ugt i32 [[INC_PEEL7]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL11]], label [[IF_THEN_PEEL13:%.*]], label [[IF_ELSE_PEEL12:%.*]]
; CHECK: if.else.peel12:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL14:%.*]]
; CHECK: if.then.peel13:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL14]]
; CHECK: for.inc.peel14:
; CHECK-NEXT: [[INC_PEEL15:%.*]] = add nsw i32 [[INC_PEEL7]], 1
; CHECK-NEXT: [[CMP_PEEL16:%.*]] = icmp slt i32 [[INC_PEEL15]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL16]], label [[FOR_BODY_PEEL_NEXT9:%.*]], label [[FOR_END]]
; Verify that MD_loop metadata is dropped.
; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
; CHECK: for.body.peel.next9:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT17:%.*]]
; CHECK: for.body.peel.next17:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL15]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 true, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: if.else:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: for.inc:
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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 ugt i32 %i.05, 2
br i1 %cmp1, label %if.then, label %if.else
if.then:
call void @f1()
br label %for.inc
if.else:
call void @f2()
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, !llvm.loop !3
for.end:
ret void
}
!3 = distinct !{!3}
; Test that we only peel off iterations if it simplifies a condition in the
; loop body after peeling at most MaxPeelCount iterations.
define void @test4(i32 %k) {
; CHECK-LABEL: @test4(
; 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 ugt i32 [[I_05]], 9999
; 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 ugt i32 %i.05, 9999
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
}
; In this test, the condition involves 2 AddRecs. Without evaluating both
; AddRecs, we cannot prove that the condition becomes known in the loop body
; after peeling.
define void @test5(i32 %k) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 4, [[ENTRY]] ], [ [[J_INC:%.*]], [[FOR_INC]] ]
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[I_05]], [[J]]
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: if.else:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: for.inc:
; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 2
; CHECK-NEXT: [[J_INC]] = add nsw i32 [[J]], 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
;
entry:
br label %for.body
for.body:
%i.05 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
%j = phi i32 [ 4, %entry ], [ %j.inc, %for.inc ]
%cmp1 = icmp ult i32 %i.05, %j
br i1 %cmp1, label %if.then, label %if.else
if.then:
call void @f1()
br label %for.inc
if.else:
call void @f2()
br label %for.inc
for.inc:
%inc = add nsw i32 %i.05, 2
%j.inc = add nsw i32 %j, 1
%cmp = icmp slt i32 %inc, %k
br i1 %cmp, label %for.body, label %for.end
for.end:
ret void
}
define void @test6(i32 %k) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ne i32 0, 3
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ne i32 [[INC_PEEL]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL4:%.*]], label [[FOR_INC_PEEL5:%.*]]
; CHECK: if.then.peel4:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL5]]
; CHECK: for.inc.peel5:
; CHECK-NEXT: [[INC_PEEL6:%.*]] = add nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL7:%.*]] = icmp slt i32 [[INC_PEEL6]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL7]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL9:%.*]]
; CHECK: for.body.peel9:
; CHECK-NEXT: [[CMP1_PEEL10:%.*]] = icmp ne i32 [[INC_PEEL6]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL10]], label [[IF_THEN_PEEL11:%.*]], label [[FOR_INC_PEEL12:%.*]]
; CHECK: if.then.peel11:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL12]]
; CHECK: for.inc.peel12:
; CHECK-NEXT: [[INC_PEEL13:%.*]] = add nsw i32 [[INC_PEEL6]], 1
; CHECK-NEXT: [[CMP_PEEL14:%.*]] = icmp slt i32 [[INC_PEEL13]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL14]], label [[FOR_BODY_PEEL_NEXT8:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next8:
; CHECK-NEXT: br label [[FOR_BODY_PEEL16:%.*]]
; CHECK: for.body.peel16:
; CHECK-NEXT: [[CMP1_PEEL17:%.*]] = icmp ne i32 [[INC_PEEL13]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL17]], label [[IF_THEN_PEEL18:%.*]], label [[FOR_INC_PEEL19:%.*]]
; CHECK: if.then.peel18:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL19]]
; CHECK: for.inc.peel19:
; CHECK-NEXT: [[INC_PEEL20:%.*]] = add nsw i32 [[INC_PEEL13]], 1
; CHECK-NEXT: [[CMP_PEEL21:%.*]] = icmp slt i32 [[INC_PEEL20]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL21]], label [[FOR_BODY_PEEL_NEXT15:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next15:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT22:%.*]]
; CHECK: for.body.peel.next22:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL20]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 true, 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 nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !6
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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, 3
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
}
define void @test7(i32 %k) {
; CHECK-LABEL: @test7(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 0, 3
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp eq i32 [[INC_PEEL]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL4:%.*]], label [[FOR_INC_PEEL5:%.*]]
; CHECK: if.then.peel4:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL5]]
; CHECK: for.inc.peel5:
; CHECK-NEXT: [[INC_PEEL6:%.*]] = add nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL7:%.*]] = icmp slt i32 [[INC_PEEL6]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL7]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL9:%.*]]
; CHECK: for.body.peel9:
; CHECK-NEXT: [[CMP1_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL6]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL10]], label [[IF_THEN_PEEL11:%.*]], label [[FOR_INC_PEEL12:%.*]]
; CHECK: if.then.peel11:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL12]]
; CHECK: for.inc.peel12:
; CHECK-NEXT: [[INC_PEEL13:%.*]] = add nsw i32 [[INC_PEEL6]], 1
; CHECK-NEXT: [[CMP_PEEL14:%.*]] = icmp slt i32 [[INC_PEEL13]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL14]], label [[FOR_BODY_PEEL_NEXT8:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next8:
; CHECK-NEXT: br label [[FOR_BODY_PEEL16:%.*]]
; CHECK: for.body.peel16:
; CHECK-NEXT: [[CMP1_PEEL17:%.*]] = icmp eq i32 [[INC_PEEL13]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL17]], label [[IF_THEN_PEEL18:%.*]], label [[FOR_INC_PEEL19:%.*]]
; CHECK: if.then.peel18:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL19]]
; CHECK: for.inc.peel19:
; CHECK-NEXT: [[INC_PEEL20:%.*]] = add nsw i32 [[INC_PEEL13]], 1
; CHECK-NEXT: [[CMP_PEEL21:%.*]] = icmp slt i32 [[INC_PEEL20]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL21]], label [[FOR_BODY_PEEL_NEXT15:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next15:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT22:%.*]]
; CHECK: for.body.peel.next22:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL20]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 false, 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 nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !7
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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, 3
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
}
define void @test8(i32 %k) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp slt i32 0, 3
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add i32 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp slt i32 [[INC_PEEL]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL4:%.*]], label [[FOR_INC_PEEL5:%.*]]
; CHECK: if.then.peel4:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL5]]
; CHECK: for.inc.peel5:
; CHECK-NEXT: [[INC_PEEL6:%.*]] = add i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL7:%.*]] = icmp slt i32 [[INC_PEEL6]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL7]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL9:%.*]]
; CHECK: for.body.peel9:
; CHECK-NEXT: [[CMP1_PEEL10:%.*]] = icmp slt i32 [[INC_PEEL6]], 3
; CHECK-NEXT: br i1 [[CMP1_PEEL10]], label [[IF_THEN_PEEL11:%.*]], label [[FOR_INC_PEEL12:%.*]]
; CHECK: if.then.peel11:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL12]]
; CHECK: for.inc.peel12:
; CHECK-NEXT: [[INC_PEEL13:%.*]] = add i32 [[INC_PEEL6]], 1
; CHECK-NEXT: [[CMP_PEEL14:%.*]] = icmp slt i32 [[INC_PEEL13]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL14]], label [[FOR_BODY_PEEL_NEXT8:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next8:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT15:%.*]]
; CHECK: for.body.peel.next15:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL13]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 false, 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 nuw nsw i32 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop [[LOOP8:![0-9]+]]
; CHECK: for.end.loopexit:
; CHECK-NEXT: br 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 slt i32 %i.05, 3
br i1 %cmp1, label %if.then, label %for.inc
if.then:
call void @f1()
br label %for.inc
for.inc:
%inc = add i32 %i.05, 1
%cmp = icmp slt i32 %inc, %k
br i1 %cmp, label %for.body, label %for.end
for.end:
ret void
}
; CHECK-NOT: llvm.loop.unroll.disable
define void @test_9__peel_first_iter_via_slt_pred(i32 %len) {
; CHECK-LABEL: @test_9__peel_first_iter_via_slt_pred(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp slt i32 0, 1
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%cmp1 = icmp slt i32 %i.06, 1
br i1 %cmp1, label %if.then, label %if.end
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
define void @test_10__peel_first_iter_via_sgt_pred(i32 %len) {
; CHECK-LABEL: @test_10__peel_first_iter_via_sgt_pred(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp sgt i32 0, 0
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_END_PEEL:%.*]], label [[IF_THEN_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 true, label [[IF_END]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%cmp1 = icmp sgt i32 %i.06, 0
br i1 %cmp1, label %if.end, label %if.then
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
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 @test11__peel_first_iter_via_eq_pred(i32 %len) {
; CHECK-LABEL: @test11__peel_first_iter_via_eq_pred(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 0, 0
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%cmp1 = icmp eq i32 %i.06, 0
br i1 %cmp1, label %if.then, label %if.end
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
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_ne_pred(i32 %len) {
; CHECK-LABEL: @test12__peel_first_iter_via_ne_pred(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ne i32 0, 0
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_END_PEEL:%.*]], label [[IF_THEN_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 true, label [[IF_END]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%cmp1 = icmp ne i32 %i.06, 0
br i1 %cmp1, label %if.end, label %if.then
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
; No peeling is profitable here.
define void @test13__ivar_mod2_is_1(i32 %len) {
; CHECK-LABEL: @test13__ivar_mod2_is_1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[I_06]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[AND]], 1
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_END]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%and = and i32 %i.06, 1
%cmp1 = icmp eq i32 %and, 1
br i1 %cmp1, label %if.end, label %if.then
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
; No peeling is profitable here.
define void @test14__ivar_mod2_is_0(i32 %len) {
; CHECK-LABEL: @test14__ivar_mod2_is_0(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[I_06]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_END]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @init()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: call void @sink()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[LEN]]
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY]]
;
entry:
%cmp5 = icmp sgt i32 %len, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.06 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%and = and i32 %i.06, 1
%cmp1 = icmp eq i32 %and, 0
br i1 %cmp1, label %if.end, label %if.then
if.then: ; preds = %for.body
call void @init()
br label %if.end
if.end: ; preds = %if.then, %for.body
call void @sink()
%inc = add nuw nsw i32 %i.06, 1
%exitcond = icmp eq i32 %inc, %len
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
; Similar to @test6, 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 @test15(i32 %k) {
; CHECK-LABEL: @test15(
; 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 @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 @test16(i32 %k) {
; CHECK-LABEL: @test16(
; 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
}
define void @test17() personality ptr undef{
; CHECK-LABEL: @test17(
; CHECK-NEXT: body:
; CHECK-NEXT: br label [[LOOP_PEEL_BEGIN:%.*]]
; CHECK: loop.peel.begin:
; CHECK-NEXT: br label [[LOOP_PEEL:%.*]]
; CHECK: loop.peel:
; CHECK-NEXT: invoke void @f1()
; CHECK-NEXT: to label [[LOOP_PEEL_NEXT:%.*]] unwind label [[EH_UNW_LOOPEXIT_LOOPEXIT_SPLIT_LP:%.*]]
; CHECK: loop.peel.next:
; CHECK-NEXT: br label [[LOOP_PEEL_NEXT1:%.*]]
; CHECK: loop.peel.next1:
; CHECK-NEXT: br label [[BODY_PEEL_NEWPH:%.*]]
; CHECK: body.peel.newph:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: invoke void @f1()
; CHECK-NEXT: to label [[LOOP]] unwind label [[EH_UNW_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP14:![0-9]+]]
; CHECK: eh.Unw.loopexit.loopexit:
; CHECK-NEXT: [[LPAD_LOOPEXIT2:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: catch ptr null
; CHECK-NEXT: br label [[EH_UNW_LOOPEXIT:%.*]]
; CHECK: eh.Unw.loopexit.loopexit.split-lp:
; CHECK-NEXT: [[LPAD_LOOPEXIT_SPLIT_LP:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: catch ptr null
; CHECK-NEXT: br label [[EH_UNW_LOOPEXIT]]
; CHECK: eh.Unw.loopexit:
; CHECK-NEXT: ret void
;
body:
br label %loop
loop:
%const = phi i64 [ -33, %loop ], [ -20, %body ]
invoke void @f1()
to label %loop unwind label %eh.Unw.loopexit
eh.Unw.loopexit:
%lpad.loopexit = landingpad { ptr, i32 }
catch ptr null
ret void
}
; Testcase reduced from PR48812.
define void @test18(ptr %p) {
; CHECK-LABEL: @test18(
; CHECK-NEXT: init:
; CHECK-NEXT: br label [[LOOP_PEEL_BEGIN:%.*]]
; CHECK: loop.peel.begin:
; CHECK-NEXT: br label [[LOOP_PEEL:%.*]]
; CHECK: loop.peel:
; CHECK-NEXT: br label [[LATCH_PEEL:%.*]]
; CHECK: latch.peel:
; CHECK-NEXT: [[CONTROL_PEEL:%.*]] = load volatile i32, ptr [[P:%.*]], align 4
; CHECK-NEXT: switch i32 [[CONTROL_PEEL]], label [[EXIT:%.*]] [
; CHECK-NEXT: i32 2, label [[LOOP_PEEL_NEXT:%.*]]
; CHECK-NEXT: ]
; CHECK: loop.peel.next:
; CHECK-NEXT: br label [[LOOP_PEEL_NEXT1:%.*]]
; CHECK: loop.peel.next1:
; CHECK-NEXT: br label [[INIT_PEEL_NEWPH:%.*]]
; CHECK: init.peel.newph:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: br label [[LATCH:%.*]]
; CHECK: latch:
; CHECK-NEXT: [[CONTROL:%.*]] = load volatile i32, ptr [[P]], align 4
; CHECK-NEXT: switch i32 [[CONTROL]], label [[EXIT_LOOPEXIT:%.*]] [
; CHECK-NEXT: i32 2, label [[LOOP]]
; CHECK-NEXT: ], !llvm.loop [[LOOP15:![0-9]+]]
; CHECK: exit.loopexit:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
init:
br label %loop
loop:
%const = phi i32 [ 40, %init ], [ 0, %latch ]
br label %latch
latch:
%control = load volatile i32, ptr %p
switch i32 %control, label %exit [
i32 2, label %loop
]
exit:
ret void
}
; Test that we can peel based on a select's condition
define void @test19(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 0, 0
; CHECK-NEXT: [[COND_PEEL:%.*]] = select i1 [[CMP1_PEEL]], i32 [[A:%.*]], i32 [[B:%.*]]
; CHECK-NEXT: tail call void @f3(i32 noundef [[COND_PEEL]])
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[INC_PEEL]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: tail call void @f3(i32 noundef [[B]])
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_06]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %num, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %for.body, %entry
ret void
for.body: ; preds = %entry, %for.body
%i.06 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
%cmp1 = icmp eq i32 %i.06, 0
%cond = select i1 %cmp1, i32 %a, i32 %b
tail call void @f3(i32 noundef %cond) #2
%inc = add nuw nsw i32 %i.06, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test we can peel based on a and's LHS condition
define void @test20(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test20(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[REM_PEEL:%.*]] = and i32 0, 1
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 [[REM_PEEL]], 0
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 3
; CHECK-NEXT: [[AND_COND_PEEL:%.*]] = and i1 [[CMP2_PEEL]], [[CMP1_PEEL]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[REM_PEEL3:%.*]] = and i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP1_PEEL4:%.*]] = icmp eq i32 [[REM_PEEL3]], 0
; CHECK-NEXT: [[CMP2_PEEL5:%.*]] = icmp ult i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[AND_COND_PEEL6:%.*]] = and i1 [[CMP2_PEEL5]], [[CMP1_PEEL4]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL6]], label [[IF_THEN_PEEL7:%.*]], label [[IF_END_PEEL8:%.*]]
; CHECK: if.then.peel7:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL8]]
; CHECK: if.end.peel8:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL9]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL10]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL12:%.*]]
; CHECK: for.body.peel12:
; CHECK-NEXT: [[REM_PEEL13:%.*]] = and i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp eq i32 [[REM_PEEL13]], 0
; CHECK-NEXT: [[CMP2_PEEL15:%.*]] = icmp ult i32 [[INC_PEEL9]], 3
; CHECK-NEXT: [[AND_COND_PEEL16:%.*]] = and i1 [[CMP2_PEEL15]], [[CMP1_PEEL14]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL16]], label [[IF_THEN_PEEL17:%.*]], label [[IF_END_PEEL18:%.*]]
; CHECK: if.then.peel17:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL18]]
; CHECK: if.end.peel18:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL19:%.*]] = add nuw nsw i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL20:%.*]] = icmp eq i32 [[INC_PEEL19]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL20]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT11:%.*]]
; CHECK: for.body.peel.next11:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT21:%.*]]
; CHECK: for.body.peel.next21:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL19]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %num, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem = and i32 %i.08, 1
%cmp1 = icmp eq i32 %rem, 0
%cmp2 = icmp ult i32 %i.08, 3
%and.cond = and i1 %cmp2, %cmp1
br i1 %and.cond, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (...) @f1()
br label %if.end
if.end: ; preds = %if.then, %for.body
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test we can peel based on a and's RHS condition
define void @test21(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test21(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[REM_PEEL:%.*]] = and i32 0, 1
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 [[REM_PEEL]], 0
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 3
; CHECK-NEXT: [[AND_COND_PEEL:%.*]] = and i1 [[CMP1_PEEL]], [[CMP2_PEEL]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[REM_PEEL3:%.*]] = and i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP1_PEEL4:%.*]] = icmp eq i32 [[REM_PEEL3]], 0
; CHECK-NEXT: [[CMP2_PEEL5:%.*]] = icmp ult i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[AND_COND_PEEL6:%.*]] = and i1 [[CMP1_PEEL4]], [[CMP2_PEEL5]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL6]], label [[IF_THEN_PEEL7:%.*]], label [[IF_END_PEEL8:%.*]]
; CHECK: if.then.peel7:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL8]]
; CHECK: if.end.peel8:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL9]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL10]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL12:%.*]]
; CHECK: for.body.peel12:
; CHECK-NEXT: [[REM_PEEL13:%.*]] = and i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp eq i32 [[REM_PEEL13]], 0
; CHECK-NEXT: [[CMP2_PEEL15:%.*]] = icmp ult i32 [[INC_PEEL9]], 3
; CHECK-NEXT: [[AND_COND_PEEL16:%.*]] = and i1 [[CMP1_PEEL14]], [[CMP2_PEEL15]]
; CHECK-NEXT: br i1 [[AND_COND_PEEL16]], label [[IF_THEN_PEEL17:%.*]], label [[IF_END_PEEL18:%.*]]
; CHECK: if.then.peel17:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END_PEEL18]]
; CHECK: if.end.peel18:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL19:%.*]] = add nuw nsw i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL20:%.*]] = icmp eq i32 [[INC_PEEL19]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL20]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT11:%.*]]
; CHECK: for.body.peel.next11:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT21:%.*]]
; CHECK: for.body.peel.next21:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL19]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (...) @f1()
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %num, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem = and i32 %i.08, 1
%cmp1 = icmp eq i32 %rem, 0
%cmp2 = icmp ult i32 %i.08, 3
%and.cond = and i1 %cmp1, %cmp2
br i1 %and.cond, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (...) @f1()
br label %if.end
if.end: ; preds = %if.then, %for.body
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test that we can peel based on a or's LHS condition
define void @test22(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test22(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[REM_PEEL:%.*]] = and i32 0, 1
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 [[REM_PEEL]], 0
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 3
; CHECK-NEXT: [[OR_COND_PEEL:%.*]] = or i1 [[CMP2_PEEL]], [[CMP1_PEEL]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A:%.*]])
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[REM_PEEL3:%.*]] = and i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP1_PEEL4:%.*]] = icmp eq i32 [[REM_PEEL3]], 0
; CHECK-NEXT: [[CMP2_PEEL5:%.*]] = icmp ult i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[OR_COND_PEEL6:%.*]] = or i1 [[CMP2_PEEL5]], [[CMP1_PEEL4]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL6]], label [[IF_THEN_PEEL7:%.*]], label [[IF_END_PEEL8:%.*]]
; CHECK: if.then.peel7:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL8]]
; CHECK: if.end.peel8:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL9]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL10]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL12:%.*]]
; CHECK: for.body.peel12:
; CHECK-NEXT: [[REM_PEEL13:%.*]] = and i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp eq i32 [[REM_PEEL13]], 0
; CHECK-NEXT: [[CMP2_PEEL15:%.*]] = icmp ult i32 [[INC_PEEL9]], 3
; CHECK-NEXT: [[OR_COND_PEEL16:%.*]] = or i1 [[CMP2_PEEL15]], [[CMP1_PEEL14]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL16]], label [[IF_THEN_PEEL17:%.*]], label [[IF_END_PEEL18:%.*]]
; CHECK: if.then.peel17:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL18]]
; CHECK: if.end.peel18:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL19:%.*]] = add nuw nsw i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL20:%.*]] = icmp eq i32 [[INC_PEEL19]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL20]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT11:%.*]]
; CHECK: for.body.peel.next11:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT21:%.*]]
; CHECK: for.body.peel.next21:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL19]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: [[REM:%.*]] = and i32 [[I_08]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[REM]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %num, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem = and i32 %i.08, 1
%cmp1 = icmp eq i32 %rem, 0
%cmp2 = icmp ult i32 %i.08, 3
%or.cond = or i1 %cmp2, %cmp1
br i1 %or.cond, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (i32, ...) @f1(i32 %a)
br label %if.end
if.end: ; preds = %for.body, %if.then
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test that we can peel based on a or's RHS condition
define void @test23(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test23(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[REM_PEEL:%.*]] = and i32 0, 1
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp eq i32 [[REM_PEEL]], 0
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 3
; CHECK-NEXT: [[OR_COND_PEEL:%.*]] = or i1 [[CMP1_PEEL]], [[CMP2_PEEL]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A:%.*]])
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[REM_PEEL3:%.*]] = and i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP1_PEEL4:%.*]] = icmp eq i32 [[REM_PEEL3]], 0
; CHECK-NEXT: [[CMP2_PEEL5:%.*]] = icmp ult i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[OR_COND_PEEL6:%.*]] = or i1 [[CMP1_PEEL4]], [[CMP2_PEEL5]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL6]], label [[IF_THEN_PEEL7:%.*]], label [[IF_END_PEEL8:%.*]]
; CHECK: if.then.peel7:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL8]]
; CHECK: if.end.peel8:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL9]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL10]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL12:%.*]]
; CHECK: for.body.peel12:
; CHECK-NEXT: [[REM_PEEL13:%.*]] = and i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp eq i32 [[REM_PEEL13]], 0
; CHECK-NEXT: [[CMP2_PEEL15:%.*]] = icmp ult i32 [[INC_PEEL9]], 3
; CHECK-NEXT: [[OR_COND_PEEL16:%.*]] = or i1 [[CMP1_PEEL14]], [[CMP2_PEEL15]]
; CHECK-NEXT: br i1 [[OR_COND_PEEL16]], label [[IF_THEN_PEEL17:%.*]], label [[IF_END_PEEL18:%.*]]
; CHECK: if.then.peel17:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL18]]
; CHECK: if.end.peel18:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL19:%.*]] = add nuw nsw i32 [[INC_PEEL9]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL20:%.*]] = icmp eq i32 [[INC_PEEL19]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL20]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT11:%.*]]
; CHECK: for.body.peel.next11:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT21:%.*]]
; CHECK: for.body.peel.next21:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL19]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: [[REM:%.*]] = and i32 [[I_08]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[REM]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP20:![0-9]+]]
;
entry:
%cmp5 = icmp sgt i32 %num, 0
br i1 %cmp5, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem = and i32 %i.08, 1
%cmp1 = icmp eq i32 %rem, 0
%cmp2 = icmp ult i32 %i.08, 3
%or.cond = or i1 %cmp1, %cmp2
br i1 %or.cond, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (i32, ...) @f1(i32 %a)
br label %if.end
if.end: ; preds = %for.body, %if.then
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test peeling when the loop is huge, >2^64
define void @test24(i128 %k) {
; CHECK-LABEL: @test24(
; CHECK-NEXT: for.body.lr.ph:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i128 0, 2
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
; CHECK: if.else.peel:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL]]
; CHECK: for.inc.peel:
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i128 0, 1
; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i128 [[INC_PEEL]], [[K:%.*]]
; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ult i128 [[INC_PEEL]], 2
; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
; CHECK: if.else.peel4:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC_PEEL6:%.*]]
; CHECK: if.then.peel5:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC_PEEL6]]
; CHECK: for.inc.peel6:
; CHECK-NEXT: [[INC_PEEL7:%.*]] = add nsw i128 [[INC_PEEL]], 1
; CHECK-NEXT: [[CMP_PEEL8:%.*]] = icmp slt i128 [[INC_PEEL7]], [[K]]
; CHECK-NEXT: br i1 [[CMP_PEEL8]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT9:%.*]]
; CHECK: for.body.peel.next9:
; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
; CHECK: for.body.lr.ph.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I_05:%.*]] = phi i128 [ [[INC_PEEL7]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
; CHECK-NEXT: call void @f1()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: if.else:
; CHECK-NEXT: call void @f2()
; CHECK-NEXT: br label [[FOR_INC]]
; CHECK: for.inc:
; CHECK-NEXT: [[INC]] = add nuw nsw i128 [[I_05]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[INC]], [[K]]
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop [[LOOP21:![0-9]+]]
; CHECK: for.end.loopexit:
; CHECK-NEXT: br label [[FOR_END]]
; CHECK: for.end:
; CHECK-NEXT: ret void
;
for.body.lr.ph:
br label %for.body
for.body:
%i.05 = phi i128 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
%cmp1 = icmp ult i128 %i.05, 2
br i1 %cmp1, label %if.then, label %if.else
if.then:
call void @f1()
br label %for.inc
if.else:
call void @f2()
br label %for.inc
for.inc:
%inc = add nsw i128 %i.05, 1
%cmp = icmp slt i128 %inc, %k
br i1 %cmp, label %for.body, label %for.end, !llvm.loop !1
for.end:
ret void
}
; Test peeling just below the recursion limit of 4
define void @test25(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test25(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP_ENTRY:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP_ENTRY]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
; CHECK: for.body.peel.begin:
; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
; CHECK: for.body.peel:
; CHECK-NEXT: [[REM1_PEEL:%.*]] = and i32 0, 1
; CHECK-NEXT: [[REM2_PEEL:%.*]] = srem i32 0, 3
; CHECK-NEXT: [[REM3_PEEL:%.*]] = srem i32 0, 7
; CHECK-NEXT: [[REM4_PEEL:%.*]] = srem i32 0, 11
; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i32 0, 3
; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp eq i32 [[REM1_PEEL]], 0
; CHECK-NEXT: [[CMP3_PEEL:%.*]] = icmp eq i32 [[REM2_PEEL]], 0
; CHECK-NEXT: [[CMP4_PEEL:%.*]] = icmp eq i32 [[REM3_PEEL]], 0
; CHECK-NEXT: [[CMP5_PEEL:%.*]] = icmp eq i32 [[REM4_PEEL]], 0
; CHECK-NEXT: [[OR_COND1_PEEL:%.*]] = or i1 [[CMP1_PEEL]], [[CMP2_PEEL]]
; CHECK-NEXT: [[OR_COND2_PEEL:%.*]] = or i1 [[OR_COND1_PEEL]], [[CMP3_PEEL]]
; CHECK-NEXT: [[OR_COND3_PEEL:%.*]] = or i1 [[OR_COND2_PEEL]], [[CMP4_PEEL]]
; CHECK-NEXT: [[OR_COND4_PEEL:%.*]] = or i1 [[OR_COND3_PEEL]], [[CMP5_PEEL]]
; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_END_PEEL:%.*]]
; CHECK: if.then.peel:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A:%.*]])
; CHECK-NEXT: br label [[IF_END_PEEL]]
; CHECK: if.end.peel:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL:%.*]] = icmp eq i32 [[INC_PEEL]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY_PEEL_NEXT:%.*]]
; CHECK: for.body.peel.next:
; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
; CHECK: for.body.peel2:
; CHECK-NEXT: [[REM1_PEEL3:%.*]] = and i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[REM2_PEEL4:%.*]] = srem i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[REM3_PEEL5:%.*]] = srem i32 [[INC_PEEL]], 7
; CHECK-NEXT: [[REM4_PEEL6:%.*]] = srem i32 [[INC_PEEL]], 11
; CHECK-NEXT: [[CMP1_PEEL7:%.*]] = icmp ult i32 [[INC_PEEL]], 3
; CHECK-NEXT: [[CMP2_PEEL8:%.*]] = icmp eq i32 [[REM1_PEEL3]], 0
; CHECK-NEXT: [[CMP3_PEEL9:%.*]] = icmp eq i32 [[REM2_PEEL4]], 0
; CHECK-NEXT: [[CMP4_PEEL10:%.*]] = icmp eq i32 [[REM3_PEEL5]], 0
; CHECK-NEXT: [[CMP5_PEEL11:%.*]] = icmp eq i32 [[REM4_PEEL6]], 0
; CHECK-NEXT: [[OR_COND1_PEEL12:%.*]] = or i1 [[CMP1_PEEL7]], [[CMP2_PEEL8]]
; CHECK-NEXT: [[OR_COND2_PEEL13:%.*]] = or i1 [[OR_COND1_PEEL12]], [[CMP3_PEEL9]]
; CHECK-NEXT: [[OR_COND3_PEEL14:%.*]] = or i1 [[OR_COND2_PEEL13]], [[CMP4_PEEL10]]
; CHECK-NEXT: [[OR_COND4_PEEL15:%.*]] = or i1 [[OR_COND3_PEEL14]], [[CMP5_PEEL11]]
; CHECK-NEXT: br i1 [[CMP1_PEEL7]], label [[IF_THEN_PEEL16:%.*]], label [[IF_END_PEEL17:%.*]]
; CHECK: if.then.peel16:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL17]]
; CHECK: if.end.peel17:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL18:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL19:%.*]] = icmp eq i32 [[INC_PEEL18]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL19]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT1:%.*]]
; CHECK: for.body.peel.next1:
; CHECK-NEXT: br label [[FOR_BODY_PEEL21:%.*]]
; CHECK: for.body.peel21:
; CHECK-NEXT: [[REM1_PEEL22:%.*]] = and i32 [[INC_PEEL18]], 1
; CHECK-NEXT: [[REM2_PEEL23:%.*]] = srem i32 [[INC_PEEL18]], 3
; CHECK-NEXT: [[REM3_PEEL24:%.*]] = srem i32 [[INC_PEEL18]], 7
; CHECK-NEXT: [[REM4_PEEL25:%.*]] = srem i32 [[INC_PEEL18]], 11
; CHECK-NEXT: [[CMP1_PEEL26:%.*]] = icmp ult i32 [[INC_PEEL18]], 3
; CHECK-NEXT: [[CMP2_PEEL27:%.*]] = icmp eq i32 [[REM1_PEEL22]], 0
; CHECK-NEXT: [[CMP3_PEEL28:%.*]] = icmp eq i32 [[REM2_PEEL23]], 0
; CHECK-NEXT: [[CMP4_PEEL29:%.*]] = icmp eq i32 [[REM3_PEEL24]], 0
; CHECK-NEXT: [[CMP5_PEEL30:%.*]] = icmp eq i32 [[REM4_PEEL25]], 0
; CHECK-NEXT: [[OR_COND1_PEEL31:%.*]] = or i1 [[CMP1_PEEL26]], [[CMP2_PEEL27]]
; CHECK-NEXT: [[OR_COND2_PEEL32:%.*]] = or i1 [[OR_COND1_PEEL31]], [[CMP3_PEEL28]]
; CHECK-NEXT: [[OR_COND3_PEEL33:%.*]] = or i1 [[OR_COND2_PEEL32]], [[CMP4_PEEL29]]
; CHECK-NEXT: [[OR_COND4_PEEL34:%.*]] = or i1 [[OR_COND3_PEEL33]], [[CMP5_PEEL30]]
; CHECK-NEXT: br i1 [[CMP1_PEEL26]], label [[IF_THEN_PEEL35:%.*]], label [[IF_END_PEEL36:%.*]]
; CHECK: if.then.peel35:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END_PEEL36]]
; CHECK: if.end.peel36:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC_PEEL37:%.*]] = add nuw nsw i32 [[INC_PEEL18]], 1
; CHECK-NEXT: [[EXITCOND_NOT_PEEL38:%.*]] = icmp eq i32 [[INC_PEEL37]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT_PEEL38]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY_PEEL_NEXT20:%.*]]
; CHECK: for.body.peel.next20:
; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT39:%.*]]
; CHECK: for.body.peel.next39:
; CHECK-NEXT: br label [[FOR_BODY_PREHEADER_PEEL_NEWPH:%.*]]
; CHECK: for.body.preheader.peel.newph:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ [[INC_PEEL37]], [[FOR_BODY_PREHEADER_PEEL_NEWPH]] ]
; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A]])
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
;
entry:
%cmp_entry = icmp sgt i32 %num, 0
br i1 %cmp_entry, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem1 = and i32 %i.08, 1
%rem2 = srem i32 %i.08, 3
%rem3 = srem i32 %i.08, 7
%rem4 = srem i32 %i.08, 11
%cmp1 = icmp ult i32 %i.08, 3
%cmp2 = icmp eq i32 %rem1, 0
%cmp3 = icmp eq i32 %rem2, 0
%cmp4 = icmp eq i32 %rem3, 0
%cmp5 = icmp eq i32 %rem4, 0
%or.cond1 = or i1 %cmp1, %cmp2
%or.cond2 = or i1 %or.cond1, %cmp3
%or.cond3 = or i1 %or.cond2, %cmp4
%or.cond4 = or i1 %or.cond3, %cmp5
br i1 %cmp1, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (i32, ...) @f1(i32 %a)
br label %if.end
if.end: ; preds = %for.body, %if.then
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
; Test peeling past the recursion limit of 4
define void @test26(i32 %num, i32 %a, i32 %b) {
; CHECK-LABEL: @test26(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP_ENTRY:%.*]] = icmp sgt i32 [[NUM:%.*]], 0
; CHECK-NEXT: br i1 [[CMP_ENTRY]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
; CHECK: for.body.preheader:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.cond.cleanup.loopexit:
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
; CHECK: for.cond.cleanup:
; CHECK-NEXT: ret void
; CHECK: for.body:
; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
; CHECK-NEXT: [[REM1:%.*]] = and i32 [[I_08]], 1
; CHECK-NEXT: [[REM2:%.*]] = srem i32 [[I_08]], 3
; CHECK-NEXT: [[REM3:%.*]] = srem i32 [[I_08]], 7
; CHECK-NEXT: [[REM4:%.*]] = srem i32 [[I_08]], 11
; CHECK-NEXT: [[REM5:%.*]] = srem i32 [[I_08]], 13
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[I_08]], 3
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[REM1]], 0
; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i32 [[REM2]], 0
; CHECK-NEXT: [[CMP4:%.*]] = icmp eq i32 [[REM3]], 0
; CHECK-NEXT: [[CMP5:%.*]] = icmp eq i32 [[REM4]], 0
; CHECK-NEXT: [[CMP6:%.*]] = icmp eq i32 [[REM5]], 0
; CHECK-NEXT: [[OR_COND1:%.*]] = or i1 [[CMP1]], [[CMP2]]
; CHECK-NEXT: [[OR_COND2:%.*]] = or i1 [[OR_COND1]], [[CMP3]]
; CHECK-NEXT: [[OR_COND3:%.*]] = or i1 [[OR_COND2]], [[CMP4]]
; CHECK-NEXT: [[OR_COND4:%.*]] = or i1 [[OR_COND3]], [[CMP5]]
; CHECK-NEXT: [[OR_COND5:%.*]] = or i1 [[OR_COND4]], [[CMP6]]
; CHECK-NEXT: br i1 [[OR_COND5]], label [[IF_THEN:%.*]], label [[IF_END]]
; CHECK: if.then:
; CHECK-NEXT: tail call void (i32, ...) @f1(i32 [[A:%.*]])
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: tail call void (...) @f2()
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[NUM]]
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY]]
;
entry:
%cmp_entry = icmp sgt i32 %num, 0
br i1 %cmp_entry, label %for.body, label %for.cond.cleanup
for.cond.cleanup: ; preds = %if.end, %entry
ret void
for.body: ; preds = %entry, %if.end
%i.08 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
%rem1 = and i32 %i.08, 1
%rem2 = srem i32 %i.08, 3
%rem3 = srem i32 %i.08, 7
%rem4 = srem i32 %i.08, 11
%rem5 = srem i32 %i.08, 13
%cmp1 = icmp ult i32 %i.08, 3
%cmp2 = icmp eq i32 %rem1, 0
%cmp3 = icmp eq i32 %rem2, 0
%cmp4 = icmp eq i32 %rem3, 0
%cmp5 = icmp eq i32 %rem4, 0
%cmp6 = icmp eq i32 %rem5, 0
%or.cond1 = or i1 %cmp1, %cmp2
%or.cond2 = or i1 %or.cond1, %cmp3
%or.cond3 = or i1 %or.cond2, %cmp4
%or.cond4 = or i1 %or.cond3, %cmp5
%or.cond5 = or i1 %or.cond4, %cmp6
br i1 %or.cond5, label %if.then, label %if.end
if.then: ; preds = %for.body
tail call void (i32, ...) @f1(i32 %a)
br label %if.end
if.end: ; preds = %for.body, %if.then
tail call void (...) @f2()
%inc = add nuw nsw i32 %i.08, 1
%exitcond.not = icmp eq i32 %inc, %num
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
declare void @init()
declare void @sink()