1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
3 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"
5 ; Aggressive Instcombine should be able to reduce width of these expressions.
7 declare i32 @use32(i32)
8 declare i32 @use64(i64)
9 declare <2 x i32> @use32_vec(<2 x i32>)
10 declare <2 x i32> @use64_vec(<2 x i64>)
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 ;; These tests check cases where expression dag post-dominated by TruncInst
14 ;; contains instruction, which has more than one usage.
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 define void @multi_uses_add(i32 %X) {
18 ; CHECK-LABEL: @multi_uses_add(
19 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
20 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[X]], 15
21 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
22 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
23 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
24 ; CHECK-NEXT: ret void
26 %A1 = zext i32 %X to i64
28 %C1 = mul i64 %B1, %B1
29 %T1 = trunc i64 %C1 to i32
30 call i32 @use32(i32 %T1)
31 ; make sure zext have another use that is not post-dominated by the TruncInst.
32 call i32 @use64(i64 %A1)
36 define void @multi_uses_or(i32 %X) {
37 ; CHECK-LABEL: @multi_uses_or(
38 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
39 ; CHECK-NEXT: [[B1:%.*]] = or i32 [[X]], 15
40 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
41 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
42 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
43 ; CHECK-NEXT: ret void
45 %A1 = zext i32 %X to i64
47 %C1 = mul i64 %B1, %B1
48 %T1 = trunc i64 %C1 to i32
49 call i32 @use32(i32 %T1)
50 ; make sure zext have another use that is not post-dominated by the TruncInst.
51 call i32 @use64(i64 %A1)
55 define void @multi_uses_xor(i32 %X) {
56 ; CHECK-LABEL: @multi_uses_xor(
57 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
58 ; CHECK-NEXT: [[B1:%.*]] = xor i32 [[X]], 15
59 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
60 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
61 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
62 ; CHECK-NEXT: ret void
64 %A1 = zext i32 %X to i64
66 %C1 = mul i64 %B1, %B1
67 %T1 = trunc i64 %C1 to i32
68 call i32 @use32(i32 %T1)
69 ; make sure zext have another use that is not post-dominated by the TruncInst.
70 call i32 @use64(i64 %A1)
74 define void @multi_uses_and(i32 %X) {
75 ; CHECK-LABEL: @multi_uses_and(
76 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
77 ; CHECK-NEXT: [[B1:%.*]] = and i32 [[X]], 15
78 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
79 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
80 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
81 ; CHECK-NEXT: ret void
83 %A1 = zext i32 %X to i64
85 %C1 = mul i64 %B1, %B1
86 %T1 = trunc i64 %C1 to i32
87 call i32 @use32(i32 %T1)
88 ; make sure zext have another use that is not post-dominated by the TruncInst.
89 call i32 @use64(i64 %A1)
93 define void @multi_uses_sub(i32 %X, i32 %Y) {
94 ; CHECK-LABEL: @multi_uses_sub(
95 ; CHECK-NEXT: [[A1:%.*]] = zext i32 [[X:%.*]] to i64
96 ; CHECK-NEXT: [[A2:%.*]] = zext i32 [[Y:%.*]] to i64
97 ; CHECK-NEXT: [[B1:%.*]] = sub i32 [[X]], [[Y]]
98 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
99 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
100 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
101 ; CHECK-NEXT: [[TMP3:%.*]] = call i32 @use64(i64 [[A2]])
102 ; CHECK-NEXT: ret void
104 %A1 = zext i32 %X to i64
105 %A2 = zext i32 %Y to i64
106 %B1 = sub i64 %A1, %A2
107 %C1 = mul i64 %B1, %B1
108 %T1 = trunc i64 %C1 to i32
109 call i32 @use32(i32 %T1)
110 ; make sure zext have another use that is not post-dominated by the TruncInst.
111 call i32 @use64(i64 %A1)
112 call i32 @use64(i64 %A2)
116 define void @multi_use_vec_add(<2 x i32> %X) {
117 ; CHECK-LABEL: @multi_use_vec_add(
118 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
119 ; CHECK-NEXT: [[B1:%.*]] = add <2 x i32> [[X]], <i32 15, i32 15>
120 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
121 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
122 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
123 ; CHECK-NEXT: ret void
125 %A1 = zext <2 x i32> %X to <2 x i64>
126 %B1 = add <2 x i64> %A1, <i64 15, i64 15>
127 %C1 = mul <2 x i64> %B1, %B1
128 %T1 = trunc <2 x i64> %C1 to <2 x i32>
129 call <2 x i32> @use32_vec(<2 x i32> %T1)
130 ; make sure zext have another use that is not post-dominated by the TruncInst.
131 call <2 x i32> @use64_vec(<2 x i64> %A1)
135 define void @multi_use_vec_or(<2 x i32> %X) {
136 ; CHECK-LABEL: @multi_use_vec_or(
137 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
138 ; CHECK-NEXT: [[B1:%.*]] = or <2 x i32> [[X]], <i32 15, i32 15>
139 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
140 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
141 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
142 ; CHECK-NEXT: ret void
144 %A1 = zext <2 x i32> %X to <2 x i64>
145 %B1 = or <2 x i64> %A1, <i64 15, i64 15>
146 %C1 = mul <2 x i64> %B1, %B1
147 %T1 = trunc <2 x i64> %C1 to <2 x i32>
148 call <2 x i32> @use32_vec(<2 x i32> %T1)
149 ; make sure zext have another use that is not post-dominated by the TruncInst.
150 call <2 x i32> @use64_vec(<2 x i64> %A1)
154 define void @multi_use_vec_xor(<2 x i32> %X) {
155 ; CHECK-LABEL: @multi_use_vec_xor(
156 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
157 ; CHECK-NEXT: [[B1:%.*]] = xor <2 x i32> [[X]], <i32 15, i32 15>
158 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
159 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
160 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
161 ; CHECK-NEXT: ret void
163 %A1 = zext <2 x i32> %X to <2 x i64>
164 %B1 = xor <2 x i64> %A1, <i64 15, i64 15>
165 %C1 = mul <2 x i64> %B1, %B1
166 %T1 = trunc <2 x i64> %C1 to <2 x i32>
167 call <2 x i32> @use32_vec(<2 x i32> %T1)
168 ; make sure zext have another use that is not post-dominated by the TruncInst.
169 call <2 x i32> @use64_vec(<2 x i64> %A1)
173 define void @multi_use_vec_and(<2 x i32> %X) {
174 ; CHECK-LABEL: @multi_use_vec_and(
175 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
176 ; CHECK-NEXT: [[B1:%.*]] = and <2 x i32> [[X]], <i32 15, i32 15>
177 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
178 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
179 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
180 ; CHECK-NEXT: ret void
182 %A1 = zext <2 x i32> %X to <2 x i64>
183 %B1 = and <2 x i64> %A1, <i64 15, i64 15>
184 %C1 = mul <2 x i64> %B1, %B1
185 %T1 = trunc <2 x i64> %C1 to <2 x i32>
186 call <2 x i32> @use32_vec(<2 x i32> %T1)
187 ; make sure zext have another use that is not post-dominated by the TruncInst.
188 call <2 x i32> @use64_vec(<2 x i64> %A1)
192 define void @multi_use_vec_sub(<2 x i32> %X, <2 x i32> %Y) {
193 ; CHECK-LABEL: @multi_use_vec_sub(
194 ; CHECK-NEXT: [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
195 ; CHECK-NEXT: [[A2:%.*]] = zext <2 x i32> [[Y:%.*]] to <2 x i64>
196 ; CHECK-NEXT: [[B1:%.*]] = sub <2 x i32> [[X]], [[Y]]
197 ; CHECK-NEXT: [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
198 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
199 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
200 ; CHECK-NEXT: [[TMP3:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A2]])
201 ; CHECK-NEXT: ret void
203 %A1 = zext <2 x i32> %X to <2 x i64>
204 %A2 = zext <2 x i32> %Y to <2 x i64>
205 %B1 = sub <2 x i64> %A1, %A2
206 %C1 = mul <2 x i64> %B1, %B1
207 %T1 = trunc <2 x i64> %C1 to <2 x i32>
208 call <2 x i32> @use32_vec(<2 x i32> %T1)
209 ; make sure zext have another use that is not post-dominated by the TruncInst.
210 call <2 x i32> @use64_vec(<2 x i64> %A1)
211 call <2 x i32> @use64_vec(<2 x i64> %A2)
215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
216 ;; These tests check cases where expression dag post-dominated by TruncInst
217 ;; contains TruncInst leaf or ZEXT/SEXT leafs which turn into TruncInst leaves.
218 ;; Check that both expressions are reduced and no TruncInst remains or (was
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 ; Notice that there are two expression patterns below:
223 ; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
224 ; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
225 ; (where %T1` is the reduced node of %T1 into trunc instruction)
226 define void @trunc_as_a_leaf(i32 %X) {
227 ; CHECK-LABEL: @trunc_as_a_leaf(
228 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[X:%.*]], 15
229 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
230 ; CHECK-NEXT: [[B2:%.*]] = add i32 [[C1]], 15
231 ; CHECK-NEXT: [[C2:%.*]] = mul i32 [[B2]], [[B2]]
232 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
233 ; CHECK-NEXT: ret void
235 %A1 = zext i32 %X to i64
236 %B1 = add i64 %A1, 15
237 %C1 = mul i64 %B1, %B1
238 %T1 = trunc i64 %C1 to i48 ; leaf trunc
239 %B2 = add i48 %T1, 15
240 %C2 = mul i48 %B2, %B2
241 %T2 = trunc i48 %C2 to i32
242 call i32 @use32(i32 %T2)
246 ; Notice that there are two expression patterns below:
247 ; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
248 ; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
249 ; (where %T1` is the reduced node of %T1 into trunc instruction)
250 define void @zext_as_a_leaf(i16 %X) {
251 ; CHECK-LABEL: @zext_as_a_leaf(
252 ; CHECK-NEXT: [[A1:%.*]] = zext i16 [[X:%.*]] to i32
253 ; CHECK-NEXT: [[B1:%.*]] = add i32 [[A1]], 15
254 ; CHECK-NEXT: [[C1:%.*]] = mul i32 [[B1]], [[B1]]
255 ; CHECK-NEXT: [[B2:%.*]] = add i32 [[C1]], 15
256 ; CHECK-NEXT: [[C2:%.*]] = mul i32 [[B2]], [[B2]]
257 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
258 ; CHECK-NEXT: ret void
260 %A1 = zext i16 %X to i48
261 %B1 = add i48 %A1, 15
262 %C1 = mul i48 %B1, %B1
263 %T1 = zext i48 %C1 to i64 ; leaf zext, which will turn into trunc
264 %B2 = add i64 %T1, 15
265 %C2 = mul i64 %B2, %B2
266 %T2 = trunc i64 %C2 to i32
267 call i32 @use32(i32 %T2)