1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i32 @test1(i1 %c, i32 %x, i32 %y) {
9 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
10 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[SUB]], i32 [[Y:%.*]]
11 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[COND]], [[X]]
12 ; CHECK-NEXT: ret i32 [[ADD]]
16 %cond = select i1 %c, i32 %sub, i32 %y
17 %add = add i32 %cond, %x
21 define i32 @test2(i1 %c, i32 %x, i32 %y) {
22 ; CHECK-LABEL: @test2(
24 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
25 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[SUB]], i32 [[X]]
26 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[COND]], [[X]]
27 ; CHECK-NEXT: ret i32 [[ADD]]
31 %cond = select i1 %c, i32 %sub, i32 %x
32 %add = add i32 %cond, %x
36 define i32 @test3(i1 %c, i32 %x, i32 %y) {
37 ; CHECK-LABEL: @test3(
39 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
40 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[SUB]], i32 1
41 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[COND]], [[X]]
42 ; CHECK-NEXT: ret i32 [[MUL]]
46 %cond = select i1 %c, i32 %sub, i32 1
47 %mul = mul i32 %cond, %x
51 define i32 @test4(i1 %c, i32 %x, i32 %y) {
52 ; CHECK-LABEL: @test4(
54 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
55 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[SUB]], i32 1
56 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[COND]], [[X]]
57 ; CHECK-NEXT: ret i32 [[MUL]]
61 %cond = select i1 %c, i32 %sub, i32 1
62 %mul = mul i32 %cond, %x
66 define i32 @test5(i1 %c, i32 %x, i32 %y) {
67 ; CHECK-LABEL: @test5(
69 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[X:%.*]], i32 0
70 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[COND]], [[X]]
71 ; CHECK-NEXT: ret i32 [[ADD]]
74 %cond = select i1 %c, i32 %x, i32 0
75 %add = add i32 %cond, %x
79 define i32 @test6(i1 %c, i32 %x, i32 %y) {
80 ; CHECK-LABEL: @test6(
82 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[X:%.*]]
83 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[COND]], [[X]]
84 ; CHECK-NEXT: ret i32 [[AND]]
87 %cond = select i1 %c, i32 7, i32 %x
88 %and = and i32 %cond, %x
92 define i32 @test7(i1 %c, i32 %x) {
93 ; CHECK-LABEL: @test7(
95 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
96 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[X]], i32 [[SUB]]
97 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[COND]]
98 ; CHECK-NEXT: ret i32 [[DIV]]
102 %cond = select i1 %c, i32 %x, i32 %sub
103 %div = sdiv i32 %x, %cond
108 define i32 @test8(i1 %c, i32 %x, i32 %y) {
109 ; CHECK-LABEL: @test8(
111 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[Y:%.*]]
112 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 42, [[COND]]
113 ; CHECK-NEXT: ret i32 [[DIV]]
116 %cond = select i1 %c, i32 7, i32 %y
117 %div = sdiv i32 42, %cond
121 define i32 @test9(i1 %c, i32 %x, i32 %y) {
122 ; CHECK-LABEL: @test9(
124 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 1, i32 [[X:%.*]]
125 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[COND]]
126 ; CHECK-NEXT: ret i32 [[SUB]]
129 %cond = select i1 %c, i32 1, i32 %x
130 %sub = sub nsw i32 0, %cond
134 define i32 @test10(i1 %c, i32 %x, i32 %y) {
135 ; CHECK-LABEL: @test10(
137 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[Y:%.*]]
138 ; CHECK-NEXT: [[DIV:%.*]] = udiv i32 42, [[COND]]
139 ; CHECK-NEXT: ret i32 [[DIV]]
142 %cond = select i1 %c, i32 7, i32 %y
143 %div = udiv i32 42, %cond
147 define i32 @test11(i1 %c, i32 %x, i32 %y) {
148 ; CHECK-LABEL: @test11(
150 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[Y:%.*]]
151 ; CHECK-NEXT: [[DIV:%.*]] = srem i32 42, [[COND]]
152 ; CHECK-NEXT: ret i32 [[DIV]]
155 %cond = select i1 %c, i32 7, i32 %y
156 %div = srem i32 42, %cond
160 define i32 @test12(i1 %c, i32 %x, i32 %y) {
161 ; CHECK-LABEL: @test12(
163 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[Y:%.*]]
164 ; CHECK-NEXT: [[DIV:%.*]] = urem i32 42, [[COND]]
165 ; CHECK-NEXT: ret i32 [[DIV]]
168 %cond = select i1 %c, i32 7, i32 %y
169 %div = urem i32 42, %cond
173 define i32 @extra_use(i1 %c, i32 %x, i32 %y) {
174 ; CHECK-LABEL: @extra_use(
176 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 1, i32 [[X:%.*]]
177 ; CHECK-NEXT: tail call void @use(i32 [[COND]])
178 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[COND]]
179 ; CHECK-NEXT: ret i32 [[SUB]]
182 %cond = select i1 %c, i32 1, i32 %x
183 tail call void @use(i32 %cond)
184 %sub = sub nsw i32 0, %cond
189 define i32 @extra_use2(i1 %c, i32 %x) {
190 ; CHECK-LABEL: @extra_use2(
192 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
193 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 [[X]], i32 [[SUB]]
194 ; CHECK-NEXT: tail call void @use(i32 [[COND]])
195 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[COND]], [[X]]
196 ; CHECK-NEXT: ret i32 [[DIV]]
200 %cond = select i1 %c, i32 %x, i32 %sub
201 tail call void @use(i32 %cond)
202 %div = sdiv i32 %cond, %x