1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; RUN: opt < %s -passes=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(ptr dereferenceable(4), i32)
9 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
10 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
12 define i32 @_Z3fooPKcjj(ptr nocapture readonly %s, i32 %len, i32 %c) {
13 ; CHECK-LABEL: @_Z3fooPKcjj(
15 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
16 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[A]])
17 ; CHECK-NEXT: store i32 -1640531527, ptr [[A]], align 4
18 ; CHECK-NEXT: [[CMP8:%.*]] = icmp ugt i32 [[LEN:%.*]], 11
19 ; CHECK-NEXT: br i1 [[CMP8]], label [[WHILE_BODY_LR_PH:%.*]], label [[WHILE_END:%.*]]
20 ; CHECK: while.body.lr.ph:
21 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
23 ; CHECK-NEXT: [[KEYLEN_010:%.*]] = phi i32 [ [[LEN]], [[WHILE_BODY_LR_PH]] ], [ [[SUB:%.*]], [[WHILE_BODY]] ]
24 ; CHECK-NEXT: [[S_ADDR_09:%.*]] = phi ptr [ [[S:%.*]], [[WHILE_BODY_LR_PH]] ], [ [[ADD_PTR:%.*]], [[WHILE_BODY]] ]
25 ; CHECK-NEXT: [[T2:%.*]] = load i32, ptr [[S_ADDR_09]], align 4
26 ; CHECK-NEXT: [[SHL_I:%.*]] = shl i32 [[T2]], 1
27 ; CHECK-NEXT: [[AND_I:%.*]] = and i32 [[SHL_I]], 16843008
28 ; CHECK-NEXT: [[T3:%.*]] = load i32, ptr [[A]], align 4
29 ; CHECK-NEXT: [[SUB_I:%.*]] = add i32 [[T3]], [[T2]]
30 ; CHECK-NEXT: [[ADD:%.*]] = sub i32 [[SUB_I]], [[AND_I]]
31 ; CHECK-NEXT: store i32 [[ADD]], ptr [[A]], align 4
32 ; CHECK-NEXT: [[ADD_PTR]] = getelementptr inbounds i8, ptr [[S_ADDR_09]], i64 12
33 ; CHECK-NEXT: [[SUB]] = add i32 [[KEYLEN_010]], -12
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[SUB]], 11
35 ; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_BODY]], label [[WHILE_COND_WHILE_END_CRIT_EDGE:%.*]]
36 ; CHECK: while.cond.while.end_crit_edge:
37 ; CHECK-NEXT: [[SUB_LCSSA:%.*]] = phi i32 [ [[SUB]], [[WHILE_BODY]] ]
38 ; CHECK-NEXT: br label [[WHILE_END]]
40 ; CHECK-NEXT: [[KEYLEN_0_LCSSA:%.*]] = phi i32 [ [[SUB_LCSSA]], [[WHILE_COND_WHILE_END_CRIT_EDGE]] ], [ [[LEN]], [[ENTRY:%.*]] ]
41 ; CHECK-NEXT: call void @_Z3mixRjj(ptr dereferenceable(4) [[A]], i32 [[KEYLEN_0_LCSSA]])
42 ; CHECK-NEXT: [[T4:%.*]] = load i32, ptr [[A]], align 4
43 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[A]])
44 ; CHECK-NEXT: ret i32 [[T4]]
47 %a = alloca i32, align 4
48 call void @llvm.lifetime.start.p0(i64 4, ptr %a)
49 store i32 -1640531527, ptr %a, align 4
50 %cmp8 = icmp ugt i32 %len, 11
51 br i1 %cmp8, label %while.body.lr.ph, label %while.end
53 while.body.lr.ph: ; preds = %entry
56 while.body: ; preds = %while.body, %while.body.lr.ph
57 %keylen.010 = phi i32 [ %len, %while.body.lr.ph ], [ %sub, %while.body ]
58 %s.addr.09 = phi ptr [ %s, %while.body.lr.ph ], [ %add.ptr, %while.body ]
59 %t2 = load i32, ptr %s.addr.09, align 4
60 %shl.i = shl i32 %t2, 1
61 %and.i = and i32 %shl.i, 16843008
62 %t3 = load i32, ptr %a, align 4
63 %sub.i = add i32 %t3, %t2
64 %add = sub i32 %sub.i, %and.i
65 store i32 %add, ptr %a, align 4
66 %add.ptr = getelementptr inbounds i8, ptr %s.addr.09, i64 12
67 %sub = add i32 %keylen.010, -12
68 %cmp = icmp ugt i32 %sub, 11
69 br i1 %cmp, label %while.body, label %while.cond.while.end_crit_edge
71 while.cond.while.end_crit_edge: ; preds = %while.body
72 %sub.lcssa = phi i32 [ %sub, %while.body ]
75 while.end: ; preds = %while.cond.while.end_crit_edge, %entry
76 %keylen.0.lcssa = phi i32 [ %sub.lcssa, %while.cond.while.end_crit_edge ], [ %len, %entry ]
77 call void @_Z3mixRjj(ptr dereferenceable(4) %a, i32 %keylen.0.lcssa)
78 %t4 = load i32, ptr %a, align 4
79 call void @llvm.lifetime.end.p0(i64 4, ptr %a)
83 define i32 @zero_backedge_count_test(i32 %unknown_init, ptr %unknown_mem) {
84 ; CHECK-LABEL: @zero_backedge_count_test(
86 ; CHECK-NEXT: br label [[LOOP:%.*]]
88 ; CHECK-NEXT: [[UNKNOWN_NEXT:%.*]] = load volatile i32, ptr [[UNKNOWN_MEM:%.*]], align 4
89 ; CHECK-NEXT: br label [[LEAVE:%.*]]
91 ; CHECK-NEXT: ret i32 [[UNKNOWN_INIT:%.*]]
97 %iv = phi i32 [ 0, %entry], [ %iv.inc, %loop ]
98 %unknown_phi = phi i32 [ %unknown_init, %entry ], [ %unknown_next, %loop ]
99 %iv.inc = add i32 %iv, 1
100 %be_taken = icmp ne i32 %iv.inc, 1
101 %unknown_next = load volatile i32, ptr %unknown_mem
102 br i1 %be_taken, label %loop, label %leave
105 ; We can fold %unknown_phi even though the backedge value for it is completely
106 ; unknown, since we can prove that the loop's backedge taken count is 0.
108 %exit_val = phi i32 [ %unknown_phi, %loop ]