1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -passes=loop-unroll -unroll-count=4 | FileCheck %s
4 ; This is a test case that required a number of setup passes because
5 ; it depends on block order.
7 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
8 target triple = "x86_64-apple-macosx10.6.8"
10 declare i1 @check() nounwind
11 declare i32 @getval() nounwind
13 ; Check that the loop exit merges values from all the iterations. This
14 ; could be a tad fragile, but it's a good test.
20 ; CHECK-NEXT: [[CALL2:%.*]] = call i32 @getval()
21 ; CHECK-NEXT: br label [[LAND_LHS_TRUE_I:%.*]]
22 ; CHECK: land.lhs.true.i:
23 ; CHECK-NEXT: [[CMP4_I:%.*]] = call zeroext i1 @check()
24 ; CHECK-NEXT: br i1 [[CMP4_I]], label [[BAR_EXIT:%.*]], label [[DO_COND:%.*]]
26 ; CHECK-NEXT: [[TMP7_I:%.*]] = call i32 @getval()
27 ; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[TMP7_I]], 0
28 ; CHECK-NEXT: br i1 [[CMP_NOT]], label [[DO_COND]], label [[LAND_LHS_TRUE:%.*]]
29 ; CHECK: land.lhs.true:
30 ; CHECK-NEXT: [[CALL10:%.*]] = call i32 @getval()
31 ; CHECK-NEXT: [[CMP11:%.*]] = icmp eq i32 [[CALL10]], 0
32 ; CHECK-NEXT: br i1 [[CMP11]], label [[RETURN:%.*]], label [[DO_COND]]
34 ; CHECK-NEXT: [[CMP18:%.*]] = icmp sgt i32 [[CALL2]], -1
35 ; CHECK-NEXT: br i1 [[CMP18]], label [[LAND_LHS_TRUE_I_1:%.*]], label [[RETURN]]
36 ; CHECK: land.lhs.true.i.1:
37 ; CHECK-NEXT: [[CMP4_I_1:%.*]] = call zeroext i1 @check()
38 ; CHECK-NEXT: br i1 [[CMP4_I_1]], label [[BAR_EXIT_1:%.*]], label [[DO_COND_1:%.*]]
40 ; CHECK-NEXT: [[TMP7_I_1:%.*]] = call i32 @getval()
41 ; CHECK-NEXT: [[CMP_NOT_1:%.*]] = icmp eq i32 [[TMP7_I_1]], 0
42 ; CHECK-NEXT: br i1 [[CMP_NOT_1]], label [[DO_COND_1]], label [[LAND_LHS_TRUE_1:%.*]]
43 ; CHECK: land.lhs.true.1:
44 ; CHECK-NEXT: [[CALL10_1:%.*]] = call i32 @getval()
45 ; CHECK-NEXT: [[CMP11_1:%.*]] = icmp eq i32 [[CALL10_1]], 0
46 ; CHECK-NEXT: br i1 [[CMP11_1]], label [[RETURN]], label [[DO_COND_1]]
48 ; CHECK-NEXT: [[CMP18_1:%.*]] = icmp sgt i32 [[CALL2]], -1
49 ; CHECK-NEXT: br i1 [[CMP18_1]], label [[LAND_LHS_TRUE_I_2:%.*]], label [[RETURN]]
50 ; CHECK: land.lhs.true.i.2:
51 ; CHECK-NEXT: [[CMP4_I_2:%.*]] = call zeroext i1 @check()
52 ; CHECK-NEXT: br i1 [[CMP4_I_2]], label [[BAR_EXIT_2:%.*]], label [[DO_COND_2:%.*]]
54 ; CHECK-NEXT: [[TMP7_I_2:%.*]] = call i32 @getval()
55 ; CHECK-NEXT: [[CMP_NOT_2:%.*]] = icmp eq i32 [[TMP7_I_2]], 0
56 ; CHECK-NEXT: br i1 [[CMP_NOT_2]], label [[DO_COND_2]], label [[LAND_LHS_TRUE_2:%.*]]
57 ; CHECK: land.lhs.true.2:
58 ; CHECK-NEXT: [[CALL10_2:%.*]] = call i32 @getval()
59 ; CHECK-NEXT: [[CMP11_2:%.*]] = icmp eq i32 [[CALL10_2]], 0
60 ; CHECK-NEXT: br i1 [[CMP11_2]], label [[RETURN]], label [[DO_COND_2]]
62 ; CHECK-NEXT: [[CMP18_2:%.*]] = icmp sgt i32 [[CALL2]], -1
63 ; CHECK-NEXT: br i1 [[CMP18_2]], label [[LAND_LHS_TRUE_I_3:%.*]], label [[RETURN]]
64 ; CHECK: land.lhs.true.i.3:
65 ; CHECK-NEXT: [[CMP4_I_3:%.*]] = call zeroext i1 @check()
66 ; CHECK-NEXT: br i1 [[CMP4_I_3]], label [[BAR_EXIT_3:%.*]], label [[DO_COND_3:%.*]]
68 ; CHECK-NEXT: [[TMP7_I_3:%.*]] = call i32 @getval()
69 ; CHECK-NEXT: [[CMP_NOT_3:%.*]] = icmp eq i32 [[TMP7_I_3]], 0
70 ; CHECK-NEXT: br i1 [[CMP_NOT_3]], label [[DO_COND_3]], label [[LAND_LHS_TRUE_3:%.*]]
71 ; CHECK: land.lhs.true.3:
72 ; CHECK-NEXT: [[CALL10_3:%.*]] = call i32 @getval()
73 ; CHECK-NEXT: [[CMP11_3:%.*]] = icmp eq i32 [[CALL10_3]], 0
74 ; CHECK-NEXT: br i1 [[CMP11_3]], label [[RETURN]], label [[DO_COND_3]]
76 ; CHECK-NEXT: [[CMP18_3:%.*]] = icmp sgt i32 [[CALL2]], -1
77 ; CHECK-NEXT: br i1 [[CMP18_3]], label [[LAND_LHS_TRUE_I]], label [[RETURN]], !llvm.loop [[LOOP0:![0-9]+]]
79 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[TMP7_I]], [[LAND_LHS_TRUE]] ], [ 0, [[DO_COND]] ], [ [[TMP7_I_1]], [[LAND_LHS_TRUE_1]] ], [ 0, [[DO_COND_1]] ], [ [[TMP7_I_2]], [[LAND_LHS_TRUE_2]] ], [ 0, [[DO_COND_2]] ], [ [[TMP7_I_3]], [[LAND_LHS_TRUE_3]] ], [ 0, [[DO_COND_3]] ]
80 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
83 %call2 = call i32 @getval()
84 br label %land.lhs.true.i
86 land.lhs.true.i: ; preds = %if.end, %do.cond
87 %cmp4.i = call zeroext i1 @check() #0
88 br i1 %cmp4.i, label %bar.exit, label %do.cond
90 bar.exit: ; preds = %land.lhs.true.i
91 %tmp7.i = call i32 @getval() #0
92 %cmp.not = icmp eq i32 %tmp7.i, 0
93 br i1 %cmp.not, label %do.cond, label %land.lhs.true
95 land.lhs.true: ; preds = %bar.exit
96 %call10 = call i32 @getval()
97 %cmp11 = icmp eq i32 %call10, 0
98 br i1 %cmp11, label %return, label %do.cond
100 do.cond: ; preds = %land.lhs.true.i, %land.lhs.true, %bar.exit
101 %cmp18 = icmp sgt i32 %call2, -1
102 br i1 %cmp18, label %land.lhs.true.i, label %return
104 return: ; preds = %do.cond, %land.lhs.true
105 %retval.0 = phi i32 [ %tmp7.i, %land.lhs.true ], [ 0, %do.cond ]