1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
6 define void @loop_pointer_iv(ptr %start, ptr %end, ptr %upper) {
7 ; CHECK-LABEL: @loop_pointer_iv(
9 ; CHECK-NEXT: [[END_LT_UPPER:%.*]] = icmp ult ptr [[END:%.*]], [[UPPER:%.*]]
10 ; CHECK-NEXT: br i1 [[END_LT_UPPER]], label [[LOOP_HEADER:%.*]], label [[EXIT:%.*]]
12 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
13 ; CHECK-NEXT: [[C_2:%.*]] = icmp ule ptr [[IV]], [[END]]
14 ; CHECK-NEXT: call void @use(i1 [[C_2]])
15 ; CHECK-NEXT: [[T_2:%.*]] = icmp uge ptr [[IV]], [[START]]
16 ; CHECK-NEXT: call void @use(i1 [[T_2]])
17 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule ptr [[IV]], [[END]]
18 ; CHECK-NEXT: br i1 [[C_1]], label [[LOOP_LATCH]], label [[EXIT]]
20 ; CHECK-NEXT: call void @use(i1 true)
21 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds i8, ptr [[IV]], i8 1
22 ; CHECK-NEXT: br label [[LOOP_HEADER]]
24 ; CHECK-NEXT: ret void
27 %end.lt.upper = icmp ult ptr %end, %upper
28 br i1 %end.lt.upper, label %loop.header, label %exit
31 %iv = phi ptr [ %start, %entry ], [ %iv.next, %loop.latch ]
32 %c.2 = icmp ule ptr %iv, %end
33 call void @use(i1 %c.2)
34 %t.2 = icmp uge ptr %iv, %start
35 call void @use(i1 %t.2)
36 %c.1 = icmp ule ptr %iv, %end
37 br i1 %c.1, label %loop.latch, label %exit
40 %t.1 = icmp ult ptr %iv, %upper
41 call void @use(i1 %t.1)
42 %iv.next = getelementptr inbounds i8, ptr %iv, i8 1
49 define void @loop_pointer_iv_null_start(ptr %end, ptr %upper) {
50 ; CHECK-LABEL: @loop_pointer_iv_null_start(
52 ; CHECK-NEXT: [[END_LT_UPPER:%.*]] = icmp ult ptr [[END:%.*]], [[UPPER:%.*]]
53 ; CHECK-NEXT: br i1 [[END_LT_UPPER]], label [[LOOP_HEADER:%.*]], label [[EXIT:%.*]]
55 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ null, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
56 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule ptr [[IV]], [[END]]
57 ; CHECK-NEXT: call void @use(i1 [[C_1]])
58 ; CHECK-NEXT: call void @use(i1 true)
59 ; CHECK-NEXT: [[C_3:%.*]] = icmp ule ptr [[IV]], [[END]]
60 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_LATCH]], label [[EXIT]]
62 ; CHECK-NEXT: call void @use(i1 true)
63 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds i8, ptr [[IV]], i8 1
64 ; CHECK-NEXT: br label [[LOOP_HEADER]]
66 ; CHECK-NEXT: ret void
69 %end.lt.upper = icmp ult ptr %end, %upper
70 br i1 %end.lt.upper, label %loop.header, label %exit
73 %iv = phi ptr [ null, %entry ], [ %iv.next, %loop.latch ]
74 %c.1 = icmp ule ptr %iv, %end
75 call void @use(i1 %c.1)
76 %c.2 = icmp uge ptr %iv, null
77 call void @use(i1 %c.2)
78 %c.3 = icmp ule ptr %iv, %end
79 br i1 %c.3, label %loop.latch, label %exit
82 %c.4 = icmp ult ptr %iv, %upper
83 call void @use(i1 %c.4)
84 %iv.next = getelementptr inbounds i8, ptr %iv, i8 1
91 define void @test_start_null_cmp_null(ptr %start) {
92 ; CHECK-LABEL: @test_start_null_cmp_null(
94 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
96 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ null, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
97 ; CHECK-NEXT: [[CMP_I_I122:%.*]] = icmp eq ptr [[IV]], null
98 ; CHECK-NEXT: br i1 [[CMP_I_I122]], label [[LOOP_LATCH]], label [[EXIT:%.*]]
100 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds i8, ptr [[IV]], i64 1
101 ; CHECK-NEXT: br label [[LOOP_HEADER]]
103 ; CHECK-NEXT: ret void
106 br label %loop.header
109 %iv = phi ptr [ null, %entry ], [ %iv.next, %loop.latch ]
110 %cmp.i.i122 = icmp eq ptr %iv, null
111 br i1 %cmp.i.i122, label %loop.latch, label %exit
114 %iv.next = getelementptr inbounds i8, ptr %iv, i64 1
115 br label %loop.header