1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-bound-split -S < %s | FileCheck %s
4 ; Previously, it caused compiler crash from verifier.
5 ; The phi node in exit block should be updated properly.
7 define i16 @test_int() {
8 ; CHECK-LABEL: @test_int(
10 ; CHECK-NEXT: br label [[ENTRY_SPLIT:%.*]]
12 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
14 ; CHECK-NEXT: [[I:%.*]] = phi i16 [ 0, [[ENTRY_SPLIT]] ], [ [[ADD:%.*]], [[COND_END:%.*]] ]
15 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i16 [[I]], 3
16 ; CHECK-NEXT: br i1 true, label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
18 ; CHECK-NEXT: br label [[COND_END]]
20 ; CHECK-NEXT: br label [[COND_END]]
22 ; CHECK-NEXT: [[CALL:%.*]] = call i16 @foo()
23 ; CHECK-NEXT: [[ADD]] = add nuw nsw i16 [[I]], 1
24 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i16 [[I]], 3
25 ; CHECK-NEXT: br i1 [[CMP2]], label [[FOR_BODY]], label [[ENTRY_SPLIT_SPLIT:%.*]]
26 ; CHECK: entry.split.split:
27 ; CHECK-NEXT: [[CALL_LCSSA_LCSSA:%.*]] = phi i16 [ [[CALL]], [[COND_END]] ]
28 ; CHECK-NEXT: [[I_LCSSA:%.*]] = phi i16 [ [[ADD]], [[COND_END]] ]
29 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ne i16 [[I_LCSSA]], 11
30 ; CHECK-NEXT: br i1 [[TMP0]], label [[FOR_BODY_SPLIT_PREHEADER:%.*]], label [[END:%.*]]
31 ; CHECK: for.body.split.preheader:
32 ; CHECK-NEXT: br label [[FOR_BODY_SPLIT:%.*]]
33 ; CHECK: for.body.split:
34 ; CHECK-NEXT: [[I_SPLIT:%.*]] = phi i16 [ [[ADD_SPLIT:%.*]], [[COND_END_SPLIT:%.*]] ], [ [[I_LCSSA]], [[FOR_BODY_SPLIT_PREHEADER]] ]
35 ; CHECK-NEXT: [[CMP1_SPLIT:%.*]] = icmp ult i16 [[I_SPLIT]], 3
36 ; CHECK-NEXT: br i1 false, label [[COND_TRUE_SPLIT:%.*]], label [[COND_FALSE_SPLIT:%.*]]
37 ; CHECK: cond.false.split:
38 ; CHECK-NEXT: br label [[COND_END_SPLIT]]
39 ; CHECK: cond.true.split:
40 ; CHECK-NEXT: br label [[COND_END_SPLIT]]
41 ; CHECK: cond.end.split:
42 ; CHECK-NEXT: [[CALL_SPLIT:%.*]] = call i16 @foo()
43 ; CHECK-NEXT: [[ADD_SPLIT]] = add nuw nsw i16 [[I_SPLIT]], 1
44 ; CHECK-NEXT: [[CMP2_SPLIT:%.*]] = icmp ult i16 [[I_SPLIT]], 11
45 ; CHECK-NEXT: br i1 [[CMP2_SPLIT]], label [[FOR_BODY_SPLIT]], label [[END_LOOPEXIT:%.*]]
46 ; CHECK: end.loopexit:
47 ; CHECK-NEXT: [[CALL_LCSSA_PH:%.*]] = phi i16 [ [[CALL_SPLIT]], [[COND_END_SPLIT]] ]
48 ; CHECK-NEXT: br label [[END]]
50 ; CHECK-NEXT: [[CALL_LCSSA:%.*]] = phi i16 [ [[CALL_LCSSA_LCSSA]], [[ENTRY_SPLIT_SPLIT]] ], [ [[CALL_LCSSA_PH]], [[END_LOOPEXIT]] ]
51 ; CHECK-NEXT: ret i16 [[CALL_LCSSA]]
56 for.body: ; preds = %entry, %cond.end
57 %i = phi i16 [ 0, %entry ], [ %add, %cond.end ]
58 %cmp1 = icmp ult i16 %i, 3
59 br i1 %cmp1, label %cond.true, label %cond.false
61 cond.true: ; preds = %for.body
64 cond.false: ; preds = %for.body
67 cond.end: ; preds = %cond.false, %cond.true
68 %call = call i16 @foo()
69 %add = add nuw nsw i16 %i, 1
70 %cmp2 = icmp ult i16 %i, 11
71 br i1 %cmp2, label %for.body, label %end
73 end: ; preds = %cond.end