1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aggressive-instcombine -S | FileCheck %s
3 ; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 ; Aggressive Instcombine should be able to reduce width of these expressions.
8 declare i32 @use32(i32)
9 declare i32 @use64(i64)
10 declare <2 x i32> @use32_vec(<2 x i32>)
11 declare <2 x i32> @use64_vec(<2 x i64>)
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 ;; These tests check cases where expression dag post-dominated by TruncInst
15 ;; contains instruction, which has more than one usage.
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 define void @multi_uses_add(i32 %X) {
19 ; CHECK-LABEL: @multi_uses_add(
20 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
21 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[X]], 15
22 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
23 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
24 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
25 ; CHECK-NEXT: ret void
27 %A1 = zext i32 %X to i64
29 %C1 = mul i64 %B1, %B1
30 %T1 = trunc i64 %C1 to i32
31 call i32 @use32(i32 %T1)
32 ; make sure zext have another use that is not post-dominated by the TruncInst.
33 call i32 @use64(i64 %A1)
37 define void @multi_uses_or(i32 %X) {
38 ; CHECK-LABEL: @multi_uses_or(
39 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
40 ; CHECK-NEXT: [[B1:%.*]] = or i32 [[X]], 15
41 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
42 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
43 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
44 ; CHECK-NEXT: ret void
46 %A1 = zext i32 %X to i64
48 %C1 = mul i64 %B1, %B1
49 %T1 = trunc i64 %C1 to i32
50 call i32 @use32(i32 %T1)
51 ; make sure zext have another use that is not post-dominated by the TruncInst.
52 call i32 @use64(i64 %A1)
56 define void @multi_uses_xor(i32 %X) {
57 ; CHECK-LABEL: @multi_uses_xor(
58 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
59 ; CHECK-NEXT: [[B1:%.*]] = xor i32 [[X]], 15
60 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
61 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
62 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
63 ; CHECK-NEXT: ret void
65 %A1 = zext i32 %X to i64
67 %C1 = mul i64 %B1, %B1
68 %T1 = trunc i64 %C1 to i32
69 call i32 @use32(i32 %T1)
70 ; make sure zext have another use that is not post-dominated by the TruncInst.
71 call i32 @use64(i64 %A1)
75 define void @multi_uses_and(i32 %X) {
76 ; CHECK-LABEL: @multi_uses_and(
77 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
78 ; CHECK-NEXT: [[B1:%.*]] = and i32 [[X]], 15
79 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
80 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
81 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
82 ; CHECK-NEXT: ret void
84 %A1 = zext i32 %X to i64
86 %C1 = mul i64 %B1, %B1
87 %T1 = trunc i64 %C1 to i32
88 call i32 @use32(i32 %T1)
89 ; make sure zext have another use that is not post-dominated by the TruncInst.
90 call i32 @use64(i64 %A1)
94 define void @multi_uses_sub(i32 %X, i32 %Y) {
95 ; CHECK-LABEL: @multi_uses_sub(
96 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
97 ; CHECK-NEXT: [[A2:%.*]] = zext i32 [[Y:%.*]] to i64
98 ; CHECK-NEXT: [[B1:%.*]] = sub i32 [[X]], [[Y]]
99 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
100 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
101 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
102 ; CHECK-NEXT: [[TMP3:%.*]] = call i32 @use64(i64 [[A2]])
103 ; CHECK-NEXT: ret void
105 %A1 = zext i32 %X to i64
106 %A2 = zext i32 %Y to i64
107 %B1 = sub i64 %A1, %A2
108 %C1 = mul i64 %B1, %B1
109 %T1 = trunc i64 %C1 to i32
110 call i32 @use32(i32 %T1)
111 ; make sure zext have another use that is not post-dominated by the TruncInst.
112 call i32 @use64(i64 %A1)
113 call i32 @use64(i64 %A2)
117 define void @multi_use_vec_add(<2 x i32> %X) {
118 ; CHECK-LABEL: @multi_use_vec_add(
119 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
120 ; CHECK-NEXT: [[B1:%.*]] = add <2 x i32> [[X]], <i32 15, i32 15>
121 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
122 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
123 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
124 ; CHECK-NEXT: ret void
126 %A1 = zext <2 x i32> %X to <2 x i64>
127 %B1 = add <2 x i64> %A1, <i64 15, i64 15>
128 %C1 = mul <2 x i64> %B1, %B1
129 %T1 = trunc <2 x i64> %C1 to <2 x i32>
130 call <2 x i32> @use32_vec(<2 x i32> %T1)
131 ; make sure zext have another use that is not post-dominated by the TruncInst.
132 call <2 x i32> @use64_vec(<2 x i64> %A1)
136 define void @multi_use_vec_or(<2 x i32> %X) {
137 ; CHECK-LABEL: @multi_use_vec_or(
138 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
139 ; CHECK-NEXT: [[B1:%.*]] = or <2 x i32> [[X]], <i32 15, i32 15>
140 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
141 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
142 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
143 ; CHECK-NEXT: ret void
145 %A1 = zext <2 x i32> %X to <2 x i64>
146 %B1 = or <2 x i64> %A1, <i64 15, i64 15>
147 %C1 = mul <2 x i64> %B1, %B1
148 %T1 = trunc <2 x i64> %C1 to <2 x i32>
149 call <2 x i32> @use32_vec(<2 x i32> %T1)
150 ; make sure zext have another use that is not post-dominated by the TruncInst.
151 call <2 x i32> @use64_vec(<2 x i64> %A1)
155 define void @multi_use_vec_xor(<2 x i32> %X) {
156 ; CHECK-LABEL: @multi_use_vec_xor(
157 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
158 ; CHECK-NEXT: [[B1:%.*]] = xor <2 x i32> [[X]], <i32 15, i32 15>
159 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
160 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
161 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
162 ; CHECK-NEXT: ret void
164 %A1 = zext <2 x i32> %X to <2 x i64>
165 %B1 = xor <2 x i64> %A1, <i64 15, i64 15>
166 %C1 = mul <2 x i64> %B1, %B1
167 %T1 = trunc <2 x i64> %C1 to <2 x i32>
168 call <2 x i32> @use32_vec(<2 x i32> %T1)
169 ; make sure zext have another use that is not post-dominated by the TruncInst.
170 call <2 x i32> @use64_vec(<2 x i64> %A1)
174 define void @multi_use_vec_and(<2 x i32> %X) {
175 ; CHECK-LABEL: @multi_use_vec_and(
176 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
177 ; CHECK-NEXT: [[B1:%.*]] = and <2 x i32> [[X]], <i32 15, i32 15>
178 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
179 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
180 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
181 ; CHECK-NEXT: ret void
183 %A1 = zext <2 x i32> %X to <2 x i64>
184 %B1 = and <2 x i64> %A1, <i64 15, i64 15>
185 %C1 = mul <2 x i64> %B1, %B1
186 %T1 = trunc <2 x i64> %C1 to <2 x i32>
187 call <2 x i32> @use32_vec(<2 x i32> %T1)
188 ; make sure zext have another use that is not post-dominated by the TruncInst.
189 call <2 x i32> @use64_vec(<2 x i64> %A1)
193 define void @multi_use_vec_sub(<2 x i32> %X, <2 x i32> %Y) {
194 ; CHECK-LABEL: @multi_use_vec_sub(
195 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
196 ; CHECK-NEXT: [[A2:%.*]] = zext <2 x i32> [[Y:%.*]] to <2 x i64>
197 ; CHECK-NEXT: [[B1:%.*]] = sub <2 x i32> [[X]], [[Y]]
198 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
199 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
200 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
201 ; CHECK-NEXT: [[TMP3:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A2]])
202 ; CHECK-NEXT: ret void
204 %A1 = zext <2 x i32> %X to <2 x i64>
205 %A2 = zext <2 x i32> %Y to <2 x i64>
206 %B1 = sub <2 x i64> %A1, %A2
207 %C1 = mul <2 x i64> %B1, %B1
208 %T1 = trunc <2 x i64> %C1 to <2 x i32>
209 call <2 x i32> @use32_vec(<2 x i32> %T1)
210 ; make sure zext have another use that is not post-dominated by the TruncInst.
211 call <2 x i32> @use64_vec(<2 x i64> %A1)
212 call <2 x i32> @use64_vec(<2 x i64> %A2)
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
217 ;; These tests check cases where expression dag post-dominated by TruncInst
218 ;; contains TruncInst leaf or ZEXT/SEXT leafs which turn into TruncInst leaves.
219 ;; Check that both expressions are reduced and no TruncInst remains or (was
221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
223 ; Notice that there are two expression patterns below:
224 ; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
225 ; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
226 ; (where %T1` is the reduced node of %T1 into trunc instruction)
227 define void @trunc_as_a_leaf(i32 %X) {
228 ; CHECK-LABEL: @trunc_as_a_leaf(
229 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[X:%.*]], 15
230 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
231 ; CHECK-NEXT: [[B2:%.*]] = add i32 [[C1]], 15
232 ; CHECK-NEXT: [[C2:%.*]] = mul i32 [[B2]], [[B2]]
233 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
234 ; CHECK-NEXT: ret void
236 %A1 = zext i32 %X to i64
237 %B1 = add i64 %A1, 15
238 %C1 = mul i64 %B1, %B1
239 %T1 = trunc i64 %C1 to i48 ; leaf trunc
240 %B2 = add i48 %T1, 15
241 %C2 = mul i48 %B2, %B2
242 %T2 = trunc i48 %C2 to i32
243 call i32 @use32(i32 %T2)
247 ; Notice that there are two expression patterns below:
248 ; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
249 ; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
250 ; (where %T1` is the reduced node of %T1 into trunc instruction)
251 define void @zext_as_a_leaf(i16 %X) {
252 ; CHECK-LABEL: @zext_as_a_leaf(
253 ; CHECK-NEXT: [[A1:%.*]] = zext i16 [[X:%.*]] to i32
254 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[A1]], 15
255 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
256 ; CHECK-NEXT: [[B2:%.*]] = add i32 [[C1]], 15
257 ; CHECK-NEXT: [[C2:%.*]] = mul i32 [[B2]], [[B2]]
258 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
259 ; CHECK-NEXT: ret void
261 %A1 = zext i16 %X to i48
262 %B1 = add i48 %A1, 15
263 %C1 = mul i48 %B1, %B1
264 %T1 = zext i48 %C1 to i64 ; leaf zext, which will turn into trunc
265 %B2 = add i64 %T1, 15
266 %C2 = mul i64 %B2, %B2
267 %T2 = trunc i64 %C2 to i32
268 call i32 @use32(i32 %T2)