• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s
2; RUN: opt -verify-loop-info -irce-print-changed-loops -passes='require<branch-prob>,irce' -S < %s 2>&1 | FileCheck %s
3
4; The test demonstrates that incorrect behavior of Clamp may lead to incorrect
5; calculation of post-loop exit condition.
6
7; CHECK-LABEL: irce: in function test_01: constrained Loop at depth 1 containing: %loop<header><exiting>,%in_bounds<exiting>,%not_zero<latch><exiting>
8; CHECK-NOT: irce: in function test_02: constrained Loop
9
10define void @test_01() {
11
12; CHECK-LABEL: test_01
13
14entry:
15  %indvars.iv.next467 = add nuw nsw i64 2, 1
16  %length.i167 = load i32, i32 addrspace(1)* undef, align 8
17  %tmp21 = zext i32 %length.i167 to i64
18  %tmp34 = load atomic i32, i32 addrspace(1)* undef unordered, align 4
19  %tmp35 = add i32 %tmp34, -9581
20  %tmp36 = icmp ugt i32 %length.i167, 1
21  br i1 %tmp36, label %preheader, label %exit
22
23exit:                                          ; preds = %in_bounds, %loop, %not_zero, %entry
24  ret void
25
26preheader:                                 ; preds = %entry
27; CHECK:      preheader:
28; CHECK-NEXT:   %length_gep.i146 = getelementptr inbounds i8, i8 addrspace(1)* undef, i64 8
29; CHECK-NEXT:   %length_gep_typed.i147 = bitcast i8 addrspace(1)* undef to i32 addrspace(1)*
30; CHECK-NEXT:   %tmp43 = icmp ult i64 %indvars.iv.next467, %tmp21
31; CHECK-NEXT:   [[C0:%[^ ]+]] = icmp ugt i64 %tmp21, 1
32; CHECK-NEXT:   %exit.mainloop.at = select i1 [[C0]], i64 %tmp21, i64 1
33; CHECK-NEXT:   [[C1:%[^ ]+]] = icmp ult i64 1, %exit.mainloop.at
34; CHECK-NEXT:   br i1 [[C1]], label %loop.preheader, label %main.pseudo.exit
35
36  %length_gep.i146 = getelementptr inbounds i8, i8 addrspace(1)* undef, i64 8
37  %length_gep_typed.i147 = bitcast i8 addrspace(1)* undef to i32 addrspace(1)*
38  %tmp43 = icmp ult i64 %indvars.iv.next467, %tmp21
39  br label %loop
40
41not_zero:                                       ; preds = %in_bounds
42; CHECK:      not_zero:
43; CHECK:        %tmp56 = icmp ult i64 %indvars.iv.next, %tmp21
44; CHECK-NEXT:   [[COND:%[^ ]+]] = icmp ult i64 %indvars.iv.next, %exit.mainloop.at
45; CHECK-NEXT:   br i1 [[COND]], label %loop, label %main.exit.selector
46
47  %tmp51 = trunc i64 %indvars.iv.next to i32
48  %tmp53 = mul i32 %tmp51, %tmp51
49  %tmp54 = add i32 %tmp53, -9582
50  %tmp55 = add i32 %tmp54, %tmp62
51  %tmp56 = icmp ult i64 %indvars.iv.next, %tmp21
52  br i1 %tmp56, label %loop, label %exit
53
54loop:                                       ; preds = %not_zero, %preheader
55  %tmp62 = phi i32 [ 1, %preheader ], [ %tmp55, %not_zero ]
56  %indvars.iv750 = phi i64 [ 1, %preheader ], [ %indvars.iv.next, %not_zero ]
57  %length.i148 = load i32, i32 addrspace(1)* %length_gep_typed.i147, align 8
58  %tmp68 = zext i32 %length.i148 to i64
59  %tmp97 = icmp ult i64 2, %tmp68
60  %or.cond = and i1 %tmp43, %tmp97
61  %tmp99 = icmp ult i64 %indvars.iv750, %tmp21
62  %or.cond1 = and i1 %or.cond, %tmp99
63  br i1 %or.cond1, label %in_bounds, label %exit
64
65in_bounds:                                       ; preds = %loop
66  %indvars.iv.next = add nuw nsw i64 %indvars.iv750, 3
67  %tmp107 = icmp ult i64 %indvars.iv.next, 2
68  br i1 %tmp107, label %not_zero, label %exit
69}
70
71define void @test_02() {
72
73; Now IRCE is smart enough to understand that the safe range here is empty.
74; Previously it executed the entire loop in safe preloop and never actually
75; entered the main loop.
76
77entry:
78  br label %loop
79
80loop:                                    ; preds = %in_bounds, %entry
81  %iv1 = phi i64 [ 3, %entry ], [ %iv1.next, %in_bounds ]
82  %iv2 = phi i64 [ 4294967295, %entry ], [ %iv2.next, %in_bounds ]
83  %iv2.offset = add i64 %iv2, 1
84  %rc = icmp ult i64 %iv2.offset, 400
85  br i1 %rc, label %in_bounds, label %bci_321
86
87bci_321:                                          ; preds = %in_bounds, %loop
88  ret void
89
90in_bounds:                                 ; preds = %loop
91  %iv1.next = add nuw nsw i64 %iv1, 2
92  %iv2.next = add nuw nsw i64 %iv2, 2
93  %cond = icmp ugt i64 %iv1, 204
94  br i1 %cond, label %bci_321, label %loop
95}
96