1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i32 @testAdd(i32 %X, i32 %Y) {
7 ; CHECK-LABEL: @testAdd(
8 ; CHECK-NEXT: [[T:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: ret i32 [[T]]
12 %tl = bitcast i32 %t to i32
16 define i32 @and_sext_to_sel(i32 %x, i1 %y) {
17 ; CHECK-LABEL: @and_sext_to_sel(
18 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y:%.*]], i32 [[X:%.*]], i32 0
19 ; CHECK-NEXT: ret i32 [[R]]
21 %sext = sext i1 %y to i32
22 %r = and i32 %sext, %x
26 define <2 x i32> @and_sext_to_sel_constant_vec(<2 x i1> %y) {
27 ; CHECK-LABEL: @and_sext_to_sel_constant_vec(
28 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> <i32 42, i32 -7>, <2 x i32> zeroinitializer
29 ; CHECK-NEXT: ret <2 x i32> [[R]]
31 %sext = sext <2 x i1> %y to <2 x i32>
32 %r = and <2 x i32> <i32 42, i32 -7>, %sext
36 define <2 x i32> @and_sext_to_sel_swap(<2 x i32> %px, <2 x i1> %y) {
37 ; CHECK-LABEL: @and_sext_to_sel_swap(
38 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i32> [[PX:%.*]], [[PX]]
39 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X]], <2 x i32> zeroinitializer
40 ; CHECK-NEXT: ret <2 x i32> [[R]]
42 %x = mul <2 x i32> %px, %px ; thwart complexity-based canonicalization
43 %sext = sext <2 x i1> %y to <2 x i32>
44 %r = and <2 x i32> %x, %sext
48 define i32 @and_sext_to_sel_multi_use(i32 %x, i1 %y) {
49 ; CHECK-LABEL: @and_sext_to_sel_multi_use(
50 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
51 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
52 ; CHECK-NEXT: [[R:%.*]] = and i32 [[SEXT]], [[X:%.*]]
53 ; CHECK-NEXT: ret i32 [[R]]
55 %sext = sext i1 %y to i32
56 call void @use(i32 %sext)
57 %r = and i32 %sext, %x
61 define i32 @and_sext_to_sel_multi_use_constant_mask(i1 %y) {
62 ; CHECK-LABEL: @and_sext_to_sel_multi_use_constant_mask(
63 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
64 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
65 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i32 42, i32 0
66 ; CHECK-NEXT: ret i32 [[R]]
68 %sext = sext i1 %y to i32
69 call void @use(i32 %sext)
70 %r = and i32 %sext, 42
74 define i32 @or_sext_to_sel(i32 %x, i1 %y) {
75 ; CHECK-LABEL: @or_sext_to_sel(
76 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y:%.*]], i32 -1, i32 [[X:%.*]]
77 ; CHECK-NEXT: ret i32 [[R]]
79 %sext = sext i1 %y to i32
84 define <2 x i32> @or_sext_to_sel_constant_vec(<2 x i1> %y) {
85 ; CHECK-LABEL: @or_sext_to_sel_constant_vec(
86 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 42, i32 -7>
87 ; CHECK-NEXT: ret <2 x i32> [[R]]
89 %sext = sext <2 x i1> %y to <2 x i32>
90 %r = or <2 x i32> <i32 42, i32 -7>, %sext
94 define <2 x i32> @or_sext_to_sel_swap(<2 x i32> %px, <2 x i1> %y) {
95 ; CHECK-LABEL: @or_sext_to_sel_swap(
96 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i32> [[PX:%.*]], [[PX]]
97 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> <i32 -1, i32 -1>, <2 x i32> [[X]]
98 ; CHECK-NEXT: ret <2 x i32> [[R]]
100 %x = mul <2 x i32> %px, %px ; thwart complexity-based canonicalization
101 %sext = sext <2 x i1> %y to <2 x i32>
102 %r = or <2 x i32> %x, %sext
106 define i32 @or_sext_to_sel_multi_use(i32 %x, i1 %y) {
107 ; CHECK-LABEL: @or_sext_to_sel_multi_use(
108 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
109 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
110 ; CHECK-NEXT: [[R:%.*]] = or i32 [[SEXT]], [[X:%.*]]
111 ; CHECK-NEXT: ret i32 [[R]]
113 %sext = sext i1 %y to i32
114 call void @use(i32 %sext)
115 %r = or i32 %sext, %x
119 define i32 @or_sext_to_sel_multi_use_constant_mask(i1 %y) {
120 ; CHECK-LABEL: @or_sext_to_sel_multi_use_constant_mask(
121 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
122 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
123 ; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i32 -1, i32 42
124 ; CHECK-NEXT: ret i32 [[R]]
126 %sext = sext i1 %y to i32
127 call void @use(i32 %sext)
128 %r = or i32 %sext, 42
132 define i32 @xor_sext_to_sel(i32 %x, i1 %y) {
133 ; CHECK-LABEL: @xor_sext_to_sel(
134 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
135 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[SEXT]], [[X:%.*]]
136 ; CHECK-NEXT: ret i32 [[R]]
138 %sext = sext i1 %y to i32
139 %r = xor i32 %sext, %x
143 define <2 x i32> @xor_sext_to_sel_constant_vec(<2 x i1> %y) {
144 ; CHECK-LABEL: @xor_sext_to_sel_constant_vec(
145 ; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[Y:%.*]] to <2 x i32>
146 ; CHECK-NEXT: [[R:%.*]] = xor <2 x i32> [[SEXT]], <i32 42, i32 -7>
147 ; CHECK-NEXT: ret <2 x i32> [[R]]
149 %sext = sext <2 x i1> %y to <2 x i32>
150 %r = xor <2 x i32> <i32 42, i32 -7>, %sext
154 define <2 x i32> @xor_sext_to_sel_swap(<2 x i32> %px, <2 x i1> %y) {
155 ; CHECK-LABEL: @xor_sext_to_sel_swap(
156 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i32> [[PX:%.*]], [[PX]]
157 ; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[Y:%.*]] to <2 x i32>
158 ; CHECK-NEXT: [[R:%.*]] = xor <2 x i32> [[X]], [[SEXT]]
159 ; CHECK-NEXT: ret <2 x i32> [[R]]
161 %x = mul <2 x i32> %px, %px ; thwart complexity-based canonicalization
162 %sext = sext <2 x i1> %y to <2 x i32>
163 %r = xor <2 x i32> %x, %sext
167 define i32 @xor_sext_to_sel_multi_use(i32 %x, i1 %y) {
168 ; CHECK-LABEL: @xor_sext_to_sel_multi_use(
169 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
170 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
171 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[SEXT]], [[X:%.*]]
172 ; CHECK-NEXT: ret i32 [[R]]
174 %sext = sext i1 %y to i32
175 call void @use(i32 %sext)
176 %r = xor i32 %sext, %x
180 define i32 @xor_sext_to_sel_multi_use_constant_mask(i1 %y) {
181 ; CHECK-LABEL: @xor_sext_to_sel_multi_use_constant_mask(
182 ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[Y:%.*]] to i32
183 ; CHECK-NEXT: call void @use(i32 [[SEXT]])
184 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[SEXT]], 42
185 ; CHECK-NEXT: ret i32 [[R]]
187 %sext = sext i1 %y to i32
188 call void @use(i32 %sext)
189 %r = xor i32 %sext, 42