Skip to content

Commit aedd47c

Browse files
RKSimonkbluck
authored andcommitted
[InstCombine][X86] Add tests for special case, constant folding and demanded elts handling for PMULH style intrinsics
1 parent 39d6563 commit aedd47c

File tree

3 files changed

+594
-0
lines changed

3 files changed

+594
-0
lines changed
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -mtriple=x86_64-unknown-unknown -S | FileCheck %s
3+
4+
;
5+
; UNDEF Elts
6+
;
7+
8+
define <8 x i16> @undef_pmulh_128(<8 x i16> %a0) {
9+
; CHECK-LABEL: @undef_pmulh_128(
10+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> [[A0:%.*]], <8 x i16> undef)
11+
; CHECK-NEXT: ret <8 x i16> [[TMP1]]
12+
;
13+
%1 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> %a0, <8 x i16> undef)
14+
ret <8 x i16> %1
15+
}
16+
17+
define <8 x i16> @undef_pmulh_128_commute(<8 x i16> %a0) {
18+
; CHECK-LABEL: @undef_pmulh_128_commute(
19+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> undef, <8 x i16> [[A0:%.*]])
20+
; CHECK-NEXT: ret <8 x i16> [[TMP1]]
21+
;
22+
%1 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> undef, <8 x i16> %a0)
23+
ret <8 x i16> %1
24+
}
25+
26+
define <16 x i16> @undef_pmulh_256(<16 x i16> %a0) {
27+
; CHECK-LABEL: @undef_pmulh_256(
28+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> [[A0:%.*]], <16 x i16> undef)
29+
; CHECK-NEXT: ret <16 x i16> [[TMP1]]
30+
;
31+
%1 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> %a0, <16 x i16> undef)
32+
ret <16 x i16> %1
33+
}
34+
35+
define <16 x i16> @undef_pmulh_256_commute(<16 x i16> %a0) {
36+
; CHECK-LABEL: @undef_pmulh_256_commute(
37+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> undef, <16 x i16> [[A0:%.*]])
38+
; CHECK-NEXT: ret <16 x i16> [[TMP1]]
39+
;
40+
%1 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> undef, <16 x i16> %a0)
41+
ret <16 x i16> %1
42+
}
43+
44+
define <32 x i16> @undef_pmulh_512(<32 x i16> %a0) {
45+
; CHECK-LABEL: @undef_pmulh_512(
46+
; CHECK-NEXT: [[TMP1:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> [[A0:%.*]], <32 x i16> undef)
47+
; CHECK-NEXT: ret <32 x i16> [[TMP1]]
48+
;
49+
%1 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> %a0, <32 x i16> undef)
50+
ret <32 x i16> %1
51+
}
52+
53+
define <32 x i16> @undef_pmulh_512_commute(<32 x i16> %a0) {
54+
; CHECK-LABEL: @undef_pmulh_512_commute(
55+
; CHECK-NEXT: [[TMP1:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> undef, <32 x i16> [[A0:%.*]])
56+
; CHECK-NEXT: ret <32 x i16> [[TMP1]]
57+
;
58+
%1 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> undef, <32 x i16> %a0)
59+
ret <32 x i16> %1
60+
}
61+
62+
;
63+
; Zero Elts
64+
;
65+
66+
define <8 x i16> @zero_pmulh_128(<8 x i16> %a0) {
67+
; CHECK-LABEL: @zero_pmulh_128(
68+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> [[A0:%.*]], <8 x i16> zeroinitializer)
69+
; CHECK-NEXT: ret <8 x i16> [[TMP1]]
70+
;
71+
%1 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> %a0, <8 x i16> zeroinitializer)
72+
ret <8 x i16> %1
73+
}
74+
75+
define <8 x i16> @zero_pmulh_128_commute(<8 x i16> %a0) {
76+
; CHECK-LABEL: @zero_pmulh_128_commute(
77+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> zeroinitializer, <8 x i16> [[A0:%.*]])
78+
; CHECK-NEXT: ret <8 x i16> [[TMP1]]
79+
;
80+
%1 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> zeroinitializer, <8 x i16> %a0)
81+
ret <8 x i16> %1
82+
}
83+
84+
define <16 x i16> @zero_pmulh_256(<16 x i16> %a0) {
85+
; CHECK-LABEL: @zero_pmulh_256(
86+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> [[A0:%.*]], <16 x i16> zeroinitializer)
87+
; CHECK-NEXT: ret <16 x i16> [[TMP1]]
88+
;
89+
%1 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> %a0, <16 x i16> zeroinitializer)
90+
ret <16 x i16> %1
91+
}
92+
93+
define <16 x i16> @zero_pmulh_256_commute(<16 x i16> %a0) {
94+
; CHECK-LABEL: @zero_pmulh_256_commute(
95+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> zeroinitializer, <16 x i16> [[A0:%.*]])
96+
; CHECK-NEXT: ret <16 x i16> [[TMP1]]
97+
;
98+
%1 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> zeroinitializer, <16 x i16> %a0)
99+
ret <16 x i16> %1
100+
}
101+
102+
define <32 x i16> @zero_pmulh_512(<32 x i16> %a0) {
103+
; CHECK-LABEL: @zero_pmulh_512(
104+
; CHECK-NEXT: [[TMP1:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> [[A0:%.*]], <32 x i16> zeroinitializer)
105+
; CHECK-NEXT: ret <32 x i16> [[TMP1]]
106+
;
107+
%1 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> %a0, <32 x i16> zeroinitializer)
108+
ret <32 x i16> %1
109+
}
110+
111+
define <32 x i16> @zero_pmulh_512_commute(<32 x i16> %a0) {
112+
; CHECK-LABEL: @zero_pmulh_512_commute(
113+
; CHECK-NEXT: [[TMP1:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> zeroinitializer, <32 x i16> [[A0:%.*]])
114+
; CHECK-NEXT: ret <32 x i16> [[TMP1]]
115+
;
116+
%1 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> zeroinitializer, <32 x i16> %a0)
117+
ret <32 x i16> %1
118+
}
119+
120+
;
121+
; Constant Folding
122+
;
123+
124+
define <8 x i16> @fold_pmulh_128() {
125+
; CHECK-LABEL: @fold_pmulh_128(
126+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> <i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8>, <8 x i16> <i16 -5, i16 7, i16 -32768, i16 32765, i16 -9, i16 -11, i16 -32763, i16 32761>)
127+
; CHECK-NEXT: ret <8 x i16> [[TMP1]]
128+
;
129+
%1 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> <i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8>, <8 x i16> <i16 -5, i16 7, i16 -32768, i16 32765, i16 -9, i16 -11, i16 -32763, i16 32761>)
130+
ret <8 x i16> %1
131+
}
132+
133+
define <16 x i16> @fold_pmulh_256() {
134+
; CHECK-LABEL: @fold_pmulh_256(
135+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> <i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15>, <16 x i16> <i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756>)
136+
; CHECK-NEXT: ret <16 x i16> [[TMP1]]
137+
;
138+
%1 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> <i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15>, <16 x i16> <i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756>)
139+
ret <16 x i16> %1
140+
}
141+
142+
define <32 x i16> @fold_pmulh_512() {
143+
; CHECK-LABEL: @fold_pmulh_512(
144+
; CHECK-NEXT: [[TMP1:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> <i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15, i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756>, <32 x i16> <i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756, i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15>)
145+
; CHECK-NEXT: ret <32 x i16> [[TMP1]]
146+
;
147+
%1 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> <i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15, i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756>, <32 x i16> <i16 -5, i16 7, i16 -32768, i16 32766, i16 -9, i16 -11, i16 -32764, i16 32762, i16 13, i16 -15, i16 -32760, i16 32758, i16 17, i16 -19, i16 -32756, i16 32756, i16 0, i16 -1, i16 2, i16 3, i16 -4, i16 -5, i16 6, i16 7, i16 -8, i16 9, i16 -10, i16 11, i16 -12, i16 13, i16 -14, i16 -15>)
148+
ret <32 x i16> %1
149+
}
150+
151+
;
152+
; Demanded Elts
153+
;
154+
155+
define <8 x i16> @elts_pmulh_128(<8 x i16> %a0, <8 x i16> %a1) {
156+
; CHECK-LABEL: @elts_pmulh_128(
157+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i16> [[A0:%.*]], <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2>
158+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i16> [[A1:%.*]], <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6>
159+
; CHECK-NEXT: [[TMP3:%.*]] = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> [[TMP1]], <8 x i16> [[TMP2]])
160+
; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <8 x i16> [[TMP3]], <8 x i16> poison, <8 x i32> zeroinitializer
161+
; CHECK-NEXT: ret <8 x i16> [[TMP4]]
162+
;
163+
%1 = shufflevector <8 x i16> %a0, <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2>
164+
%2 = shufflevector <8 x i16> %a1, <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6>
165+
%3 = call <8 x i16> @llvm.x86.sse2.pmulh.w(<8 x i16> %1, <8 x i16> %2)
166+
%4 = shufflevector <8 x i16> %3, <8 x i16> poison, <8 x i32> zeroinitializer
167+
ret <8 x i16> %4
168+
}
169+
170+
define <16 x i16> @elts_pmulh_256(<16 x i16> %a0, <16 x i16> %a1) {
171+
; CHECK-LABEL: @elts_pmulh_256(
172+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x i16> [[A0:%.*]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
173+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <16 x i16> [[A1:%.*]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
174+
; CHECK-NEXT: [[TMP3:%.*]] = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> [[TMP1]], <16 x i16> [[TMP2]])
175+
; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <16 x i32> zeroinitializer
176+
; CHECK-NEXT: ret <16 x i16> [[TMP4]]
177+
;
178+
%1 = shufflevector <16 x i16> %a0, <16 x i16> undef, <16 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
179+
%2 = shufflevector <16 x i16> %a1, <16 x i16> undef, <16 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
180+
%3 = call <16 x i16> @llvm.x86.avx2.pmulh.w(<16 x i16> %1, <16 x i16> %2)
181+
%4 = shufflevector <16 x i16> %3, <16 x i16> poison, <16 x i32> zeroinitializer
182+
ret <16 x i16> %4
183+
}
184+
185+
define <32 x i16> @elts_pmulh_512(<32 x i16> %a0, <32 x i16> %a1) {
186+
; CHECK-LABEL: @elts_pmulh_512(
187+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <32 x i16> [[A0:%.*]], <32 x i16> poison, <32 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
188+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <32 x i16> [[A1:%.*]], <32 x i16> poison, <32 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
189+
; CHECK-NEXT: [[TMP3:%.*]] = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> [[TMP1]], <32 x i16> [[TMP2]])
190+
; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <32 x i16> [[TMP3]], <32 x i16> poison, <32 x i32> zeroinitializer
191+
; CHECK-NEXT: ret <32 x i16> [[TMP4]]
192+
;
193+
%1 = shufflevector <32 x i16> %a0, <32 x i16> undef, <32 x i32> <i32 0, i32 1, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
194+
%2 = shufflevector <32 x i16> %a1, <32 x i16> undef, <32 x i32> <i32 0, i32 1, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
195+
%3 = call <32 x i16> @llvm.x86.avx512.pmulh.w.512(<32 x i16> %1, <32 x i16> %2)
196+
%4 = shufflevector <32 x i16> %3, <32 x i16> poison, <32 x i32> zeroinitializer
197+
ret <32 x i16> %4
198+
}

0 commit comments

Comments
 (0)