1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; RUN: opt < %s -indvars -loop-deletion -S | FileCheck %s
5 ; Check IndVarSimplify should not replace exit value because or else
6 ; udiv will be introduced by expand and the cost will be high.
8 declare void @_Z3mixRjj(i32* dereferenceable(4), i32)
9 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
10 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
12 define i32 @_Z3fooPKcjj(i8* nocapture readonly %s, i32 %len, i32 %c) {
13 ; CHECK-LABEL: @_Z3fooPKcjj(
15 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
16 ; CHECK-NEXT: [[T:%.*]] = bitcast i32* [[A]] to i8*
17 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[T]])
18 ; CHECK-NEXT: store i32 -1640531527, i32* [[A]], align 4
19 ; CHECK-NEXT: [[CMP8:%.*]] = icmp ugt i32 [[LEN:%.*]], 11
20 ; CHECK-NEXT: br i1 [[CMP8]], label [[WHILE_BODY_LR_PH:%.*]], label [[WHILE_END:%.*]]
21 ; CHECK: while.body.lr.ph:
22 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
24 ; CHECK-NEXT: [[KEYLEN_010:%.*]] = phi i32 [ [[LEN]], [[WHILE_BODY_LR_PH]] ], [ [[SUB:%.*]], [[WHILE_BODY]] ]
25 ; CHECK-NEXT: [[S_ADDR_09:%.*]] = phi i8* [ [[S:%.*]], [[WHILE_BODY_LR_PH]] ], [ [[ADD_PTR:%.*]], [[WHILE_BODY]] ]
26 ; CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[S_ADDR_09]] to i32*
27 ; CHECK-NEXT: [[T2:%.*]] = load i32, i32* [[T1]], align 4
28 ; CHECK-NEXT: [[SHL_I:%.*]] = shl i32 [[T2]], 1
29 ; CHECK-NEXT: [[AND_I:%.*]] = and i32 [[SHL_I]], 16843008
30 ; CHECK-NEXT: [[T3:%.*]] = load i32, i32* [[A]], align 4
31 ; CHECK-NEXT: [[SUB_I:%.*]] = add i32 [[T3]], [[T2]]
32 ; CHECK-NEXT: [[ADD:%.*]] = sub i32 [[SUB_I]], [[AND_I]]
33 ; CHECK-NEXT: store i32 [[ADD]], i32* [[A]], align 4
34 ; CHECK-NEXT: [[ADD_PTR]] = getelementptr inbounds i8, i8* [[S_ADDR_09]], i64 12
35 ; CHECK-NEXT: [[SUB]] = add i32 [[KEYLEN_010]], -12
36 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[SUB]], 11
37 ; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_BODY]], label [[WHILE_COND_WHILE_END_CRIT_EDGE:%.*]]
38 ; CHECK: while.cond.while.end_crit_edge:
39 ; CHECK-NEXT: [[SUB_LCSSA:%.*]] = phi i32 [ [[SUB]], [[WHILE_BODY]] ]
40 ; CHECK-NEXT: br label [[WHILE_END]]
42 ; CHECK-NEXT: [[KEYLEN_0_LCSSA:%.*]] = phi i32 [ [[SUB_LCSSA]], [[WHILE_COND_WHILE_END_CRIT_EDGE]] ], [ [[LEN]], [[ENTRY:%.*]] ]
43 ; CHECK-NEXT: call void @_Z3mixRjj(i32* dereferenceable(4) [[A]], i32 [[KEYLEN_0_LCSSA]])
44 ; CHECK-NEXT: [[T4:%.*]] = load i32, i32* [[A]], align 4
45 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* [[T]])
46 ; CHECK-NEXT: ret i32 [[T4]]
49 %a = alloca i32, align 4
50 %t = bitcast i32* %a to i8*
51 call void @llvm.lifetime.start.p0i8(i64 4, i8* %t)
52 store i32 -1640531527, i32* %a, align 4
53 %cmp8 = icmp ugt i32 %len, 11
54 br i1 %cmp8, label %while.body.lr.ph, label %while.end
56 while.body.lr.ph: ; preds = %entry
59 while.body: ; preds = %while.body, %while.body.lr.ph
60 %keylen.010 = phi i32 [ %len, %while.body.lr.ph ], [ %sub, %while.body ]
61 %s.addr.09 = phi i8* [ %s, %while.body.lr.ph ], [ %add.ptr, %while.body ]
62 %t1 = bitcast i8* %s.addr.09 to i32*
63 %t2 = load i32, i32* %t1, align 4
64 %shl.i = shl i32 %t2, 1
65 %and.i = and i32 %shl.i, 16843008
66 %t3 = load i32, i32* %a, align 4
67 %sub.i = add i32 %t3, %t2
68 %add = sub i32 %sub.i, %and.i
69 store i32 %add, i32* %a, align 4
70 %add.ptr = getelementptr inbounds i8, i8* %s.addr.09, i64 12
71 %sub = add i32 %keylen.010, -12
72 %cmp = icmp ugt i32 %sub, 11
73 br i1 %cmp, label %while.body, label %while.cond.while.end_crit_edge
75 while.cond.while.end_crit_edge: ; preds = %while.body
76 %sub.lcssa = phi i32 [ %sub, %while.body ]
79 while.end: ; preds = %while.cond.while.end_crit_edge, %entry
80 %keylen.0.lcssa = phi i32 [ %sub.lcssa, %while.cond.while.end_crit_edge ], [ %len, %entry ]
81 call void @_Z3mixRjj(i32* dereferenceable(4) %a, i32 %keylen.0.lcssa)
82 %t4 = load i32, i32* %a, align 4
83 call void @llvm.lifetime.end.p0i8(i64 4, i8* %t)
87 define i32 @zero_backedge_count_test(i32 %unknown_init, i32* %unknown_mem) {
88 ; CHECK-LABEL: @zero_backedge_count_test(
90 ; CHECK-NEXT: br label [[LOOP:%.*]]
92 ; CHECK-NEXT: [[UNKNOWN_NEXT:%.*]] = load volatile i32, i32* [[UNKNOWN_MEM:%.*]], align 4
93 ; CHECK-NEXT: br i1 false, label [[LOOP_LOOP_CRIT_EDGE:%.*]], label [[LEAVE:%.*]]
94 ; CHECK: loop.loop_crit_edge:
95 ; CHECK-NEXT: unreachable
97 ; CHECK-NEXT: ret i32 [[UNKNOWN_INIT:%.*]]
103 %iv = phi i32 [ 0, %entry], [ %iv.inc, %loop ]
104 %unknown_phi = phi i32 [ %unknown_init, %entry ], [ %unknown_next, %loop ]
105 %iv.inc = add i32 %iv, 1
106 %be_taken = icmp ne i32 %iv.inc, 1
107 %unknown_next = load volatile i32, i32* %unknown_mem
108 br i1 %be_taken, label %loop, label %leave
111 ; We can fold %unknown_phi even though the backedge value for it is completely
112 ; unknown, since we can prove that the loop's backedge taken count is 0.
114 %exit_val = phi i32 [ %unknown_phi, %loop ]