1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare void @use.i1(i1)
5 declare void @use.i8(i8)
6 define i8 @replace_with_y_noundef(i8 %x, i8 noundef %y, i8 %z) {
7 ; CHECK-LABEL: @replace_with_y_noundef(
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[Z:%.*]]
10 ; CHECK-NEXT: ret i8 [[SEL]]
12 %cmp = icmp eq i8 %x, %y
14 %sel = select i1 %cmp, i8 %and, i8 %z
18 define i8 @replace_with_x_noundef(i8 noundef %x, i8 %y, i8 %z) {
19 ; CHECK-LABEL: @replace_with_x_noundef(
20 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]
21 ; CHECK-NEXT: call void @use.i1(i1 [[CMP]])
22 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[X]]
23 ; CHECK-NEXT: ret i8 [[SEL]]
25 %cmp = icmp ne i8 %x, %y
26 call void @use.i1(i1 %cmp)
28 %sel = select i1 %cmp, i8 %z, i8 %and
32 define i8 @replace_with_x_maybe_undef_fail(i8 %x, i8 %y, i8 %z) {
33 ; CHECK-LABEL: @replace_with_x_maybe_undef_fail(
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: call void @use.i1(i1 [[CMP]])
36 ; CHECK-NEXT: [[AND:%.*]] = or i8 [[X]], [[Y]]
37 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[AND]]
38 ; CHECK-NEXT: ret i8 [[SEL]]
40 %cmp = icmp ne i8 %x, %y
41 call void @use.i1(i1 %cmp)
43 %sel = select i1 %cmp, i8 %z, i8 %and
47 define i8 @replace_with_y_for_new_oneuse(i8 noundef %xx, i8 noundef %y, i8 %z) {
48 ; CHECK-LABEL: @replace_with_y_for_new_oneuse(
49 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
50 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
51 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Y]]
52 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]
53 ; CHECK-NEXT: ret i8 [[SEL]]
56 %cmp = icmp eq i8 %x, %y
57 %add = add nuw i8 %x, %y
58 %sel = select i1 %cmp, i8 %add, i8 %z
62 define i8 @replace_with_y_for_new_oneuse2(i8 %xx, i8 noundef %y, i8 %z, i8 %q) {
63 ; CHECK-LABEL: @replace_with_y_for_new_oneuse2(
64 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
65 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
66 ; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Q:%.*]]
67 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]
68 ; CHECK-NEXT: ret i8 [[SEL]]
71 %cmp = icmp eq i8 %x, %y
72 %add = add nuw i8 %x, %q
73 %sel = select i1 %cmp, i8 %add, i8 %z
77 define i8 @replace_with_x_for_new_oneuse(i8 noundef %xx, i8 noundef %yy, i8 %z, i8 %w) {
78 ; CHECK-LABEL: @replace_with_x_for_new_oneuse(
79 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
80 ; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
81 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
82 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
83 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
84 ; CHECK-NEXT: ret i8 [[SEL]]
88 %cmp = icmp eq i8 %x, %y
90 %sel = select i1 %cmp, i8 %mul, i8 %z
94 define i8 @replace_with_x_for_new_oneuse2(i8 noundef %xx, i8 %yy, i8 %z, i8 %w, i8 %q) {
95 ; CHECK-LABEL: @replace_with_x_for_new_oneuse2(
96 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
97 ; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
98 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
99 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[Y]], [[Q:%.*]]
100 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
101 ; CHECK-NEXT: ret i8 [[SEL]]
105 %cmp = icmp eq i8 %x, %y
107 %sel = select i1 %cmp, i8 %mul, i8 %z
111 define i8 @replace_with_x_for_simple_binop(i8 noundef %xx, i8 %yy, i8 %z, i8 %w) {
112 ; CHECK-LABEL: @replace_with_x_for_simple_binop(
113 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
114 ; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
115 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
116 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
117 ; CHECK-NEXT: call void @use.i8(i8 [[Y]])
118 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
119 ; CHECK-NEXT: ret i8 [[SEL]]
123 %cmp = icmp eq i8 %x, %y
125 call void @use.i8(i8 %y)
126 %sel = select i1 %cmp, i8 %mul, i8 %z
130 define i8 @replace_with_none_for_new_oneuse_fail_maybe_undef(i8 %xx, i8 %y, i8 %z) {
131 ; CHECK-LABEL: @replace_with_none_for_new_oneuse_fail_maybe_undef(
132 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
133 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
134 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
135 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
136 ; CHECK-NEXT: ret i8 [[SEL]]
139 %cmp = icmp eq i8 %x, %y
141 %sel = select i1 %cmp, i8 %mul, i8 %z
145 define i8 @replace_with_y_for_simple_binop(i8 %x, i8 noundef %y, i8 %z) {
146 ; CHECK-LABEL: @replace_with_y_for_simple_binop(
147 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
148 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
149 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
150 ; CHECK-NEXT: ret i8 [[SEL]]
152 %cmp = icmp eq i8 %x, %y
153 %mul = mul nsw i8 %x, %y
154 %sel = select i1 %cmp, i8 %mul, i8 %z
158 define i8 @replace_with_y_for_simple_binop_fail_multiuse(i8 %x, i8 noundef %y, i8 %z) {
159 ; CHECK-LABEL: @replace_with_y_for_simple_binop_fail_multiuse(
160 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
161 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
162 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
163 ; CHECK-NEXT: call void @use.i8(i8 [[MUL]])
164 ; CHECK-NEXT: ret i8 [[SEL]]
166 %cmp = icmp eq i8 %x, %y
167 %mul = mul nsw i8 %x, %y
168 %sel = select i1 %cmp, i8 %mul, i8 %z
169 call void @use.i8(i8 %mul)
173 define i8 @replace_with_y_for_simple_binop_fail(i8 %x, i8 noundef %y, i8 %z, i8 %q) {
174 ; CHECK-LABEL: @replace_with_y_for_simple_binop_fail(
175 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
176 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Q:%.*]]
177 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
178 ; CHECK-NEXT: ret i8 [[SEL]]
180 %cmp = icmp eq i8 %x, %y
181 %mul = mul nsw i8 %x, %q
182 %sel = select i1 %cmp, i8 %mul, i8 %z