1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 target datalayout = "p:32:32"
6 define i32 @infer_range_from_dom_equality(i32 %x, i32 %y) {
7 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_equality(
8 ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
9 ; CHECK-NEXT: [[ENTRY:.*:]]
10 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X]], [[Y]]
11 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
12 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
14 ; CHECK-NEXT: ret i32 1
16 ; CHECK-NEXT: ret i32 [[SUB]]
19 %cond = icmp eq i32 %x, %y
21 br i1 %cond, label %if.then, label %if.else
24 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
28 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
32 define i32 @infer_range_from_dom_equality_commuted1(i32 %x, i32 %y) {
33 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_equality_commuted1(
34 ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
35 ; CHECK-NEXT: [[ENTRY:.*:]]
36 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X]], [[Y]]
37 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[Y]], [[X]]
38 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
40 ; CHECK-NEXT: ret i32 1
42 ; CHECK-NEXT: ret i32 [[SUB]]
45 %cond = icmp eq i32 %x, %y
47 br i1 %cond, label %if.then, label %if.else
50 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
54 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
58 define i32 @infer_range_from_dom_equality_commuted2(i32 %x, i32 %y) {
59 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_equality_commuted2(
60 ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
61 ; CHECK-NEXT: [[ENTRY:.*:]]
62 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[Y]], [[X]]
63 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
64 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
66 ; CHECK-NEXT: ret i32 1
68 ; CHECK-NEXT: ret i32 [[SUB]]
71 %cond = icmp eq i32 %y, %x
73 br i1 %cond, label %if.then, label %if.else
76 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
80 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
84 define i32 @infer_range_from_dom_equality_ptrdiff(ptr %x, ptr %y) {
85 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_equality_ptrdiff(
86 ; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]]) {
87 ; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[X]], [[Y]]
88 ; CHECK-NEXT: [[XI:%.*]] = ptrtoint ptr [[X]] to i32
89 ; CHECK-NEXT: [[YI:%.*]] = ptrtoint ptr [[Y]] to i32
90 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XI]], [[YI]]
91 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
93 ; CHECK-NEXT: ret i32 1
95 ; CHECK-NEXT: ret i32 [[SUB]]
97 %cond = icmp eq ptr %x, %y
98 %xi = ptrtoint ptr %x to i32
99 %yi = ptrtoint ptr %y to i32
100 %sub = sub i32 %xi, %yi
101 br i1 %cond, label %if.then, label %if.else
104 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
108 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
114 define i32 @infer_range_from_dom_slt(i32 %x, i32 %y) {
115 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_slt(
116 ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
117 ; CHECK-NEXT: [[ENTRY:.*:]]
118 ; CHECK-NEXT: [[COND:%.*]] = icmp slt i32 [[X]], [[Y]]
119 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
120 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
121 ; CHECK: [[IF_THEN]]:
122 ; CHECK-NEXT: [[MAX1:%.*]] = call i32 @llvm.umax.i32(i32 [[SUB]], i32 1)
123 ; CHECK-NEXT: ret i32 [[MAX1]]
124 ; CHECK: [[IF_ELSE]]:
125 ; CHECK-NEXT: [[MAX2:%.*]] = call i32 @llvm.umax.i32(i32 [[SUB]], i32 1)
126 ; CHECK-NEXT: ret i32 [[MAX2]]
129 %cond = icmp slt i32 %x, %y
130 %sub = sub i32 %x, %y
131 br i1 %cond, label %if.then, label %if.else
134 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
138 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
142 define i32 @infer_range_from_dom_equality_not_match(i32 %x, i32 %y, i32 %z) {
143 ; CHECK-LABEL: define range(i32 1, 0) i32 @infer_range_from_dom_equality_not_match(
144 ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
145 ; CHECK-NEXT: [[ENTRY:.*:]]
146 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X]], [[Z]]
147 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
148 ; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
149 ; CHECK: [[IF_THEN]]:
150 ; CHECK-NEXT: [[MAX1:%.*]] = call i32 @llvm.umax.i32(i32 [[SUB]], i32 1)
151 ; CHECK-NEXT: ret i32 [[MAX1]]
152 ; CHECK: [[IF_ELSE]]:
153 ; CHECK-NEXT: [[MAX2:%.*]] = call i32 @llvm.umax.i32(i32 [[SUB]], i32 1)
154 ; CHECK-NEXT: ret i32 [[MAX2]]
157 %cond = icmp eq i32 %x, %z
158 %sub = sub i32 %x, %y
159 br i1 %cond, label %if.then, label %if.else
162 %max1 = call i32 @llvm.umax.i32(i32 %sub, i32 1)
166 %max2 = call i32 @llvm.umax.i32(i32 %sub, i32 1)