Skip to content

Commit aaeb4af

Browse files
rotaterightmemfrob
authored andcommitted
[PhaseOrdering] add tests for x86 horizontal math ops (PR41813); NFC
1 parent c3fad4f commit aaeb4af

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -O3 -S < %s | FileCheck %s
3+
; RUN: opt -passes='default<O3>' -S < %s | FileCheck %s
4+
5+
target triple = "x86_64--"
6+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7+
8+
; PR41813 - https://bugs.llvm.org/show_bug.cgi?id=41813
9+
10+
define <4 x float> @hadd_reverse_v4f32(<4 x float> %a, <4 x float> %b) #0 {
11+
; CHECK-LABEL: @hadd_reverse_v4f32(
12+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[A:%.*]], <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 3, i32 undef>
13+
; CHECK-NEXT: [[TMP2:%.*]] = fadd <4 x float> [[TMP1]], [[A]]
14+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[A]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
15+
; CHECK-NEXT: [[TMP4:%.*]] = fadd <4 x float> [[TMP3]], [[A]]
16+
; CHECK-NEXT: [[VECINIT6:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> [[TMP4]], <4 x i32> <i32 2, i32 4, i32 undef, i32 undef>
17+
; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[B:%.*]], <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 3, i32 undef>
18+
; CHECK-NEXT: [[TMP6:%.*]] = fadd <4 x float> [[TMP5]], [[B]]
19+
; CHECK-NEXT: [[VECINIT10:%.*]] = shufflevector <4 x float> [[VECINIT6]], <4 x float> [[TMP6]], <4 x i32> <i32 0, i32 1, i32 6, i32 undef>
20+
; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <4 x float> [[B]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
21+
; CHECK-NEXT: [[TMP8:%.*]] = fadd <4 x float> [[TMP7]], [[B]]
22+
; CHECK-NEXT: [[VECINIT14:%.*]] = shufflevector <4 x float> [[VECINIT10]], <4 x float> [[TMP8]], <4 x i32> <i32 0, i32 1, i32 2, i32 4>
23+
; CHECK-NEXT: ret <4 x float> [[VECINIT14]]
24+
;
25+
%shuffle = shufflevector <4 x float> %a, <4 x float> %a, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
26+
%shuffle1 = shufflevector <4 x float> %b, <4 x float> %b, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
27+
%vecext = extractelement <4 x float> %shuffle, i32 0
28+
%vecext2 = extractelement <4 x float> %shuffle, i32 1
29+
%add = fadd float %vecext, %vecext2
30+
%vecinit = insertelement <4 x float> undef, float %add, i32 0
31+
%vecext3 = extractelement <4 x float> %shuffle, i32 2
32+
%vecext4 = extractelement <4 x float> %shuffle, i32 3
33+
%add5 = fadd float %vecext3, %vecext4
34+
%vecinit6 = insertelement <4 x float> %vecinit, float %add5, i32 1
35+
%vecext7 = extractelement <4 x float> %shuffle1, i32 0
36+
%vecext8 = extractelement <4 x float> %shuffle1, i32 1
37+
%add9 = fadd float %vecext7, %vecext8
38+
%vecinit10 = insertelement <4 x float> %vecinit6, float %add9, i32 2
39+
%vecext11 = extractelement <4 x float> %shuffle1, i32 2
40+
%vecext12 = extractelement <4 x float> %shuffle1, i32 3
41+
%add13 = fadd float %vecext11, %vecext12
42+
%vecinit14 = insertelement <4 x float> %vecinit10, float %add13, i32 3
43+
ret <4 x float> %vecinit14
44+
}
45+
46+
define <4 x float> @reverse_hadd_v4f32(<4 x float> %a, <4 x float> %b) #0 {
47+
; CHECK-LABEL: @reverse_hadd_v4f32(
48+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[A:%.*]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
49+
; CHECK-NEXT: [[TMP2:%.*]] = fadd <4 x float> [[TMP1]], [[A]]
50+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[A]], <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 3, i32 undef>
51+
; CHECK-NEXT: [[TMP4:%.*]] = fadd <4 x float> [[TMP3]], [[A]]
52+
; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> [[TMP4]], <4 x i32> <i32 undef, i32 undef, i32 6, i32 0>
53+
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x float> [[B:%.*]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
54+
; CHECK-NEXT: [[TMP7:%.*]] = fadd <4 x float> [[TMP6]], [[B]]
55+
; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <4 x float> [[TMP5]], <4 x float> [[TMP7]], <4 x i32> <i32 undef, i32 4, i32 2, i32 3>
56+
; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x float> [[B]], <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 3, i32 undef>
57+
; CHECK-NEXT: [[TMP10:%.*]] = fadd <4 x float> [[TMP9]], [[B]]
58+
; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <4 x float> [[TMP8]], <4 x float> [[TMP10]], <4 x i32> <i32 6, i32 1, i32 2, i32 3>
59+
; CHECK-NEXT: ret <4 x float> [[TMP11]]
60+
;
61+
%vecext = extractelement <4 x float> %a, i32 0
62+
%vecext1 = extractelement <4 x float> %a, i32 1
63+
%add = fadd float %vecext, %vecext1
64+
%vecinit = insertelement <4 x float> undef, float %add, i32 0
65+
%vecext2 = extractelement <4 x float> %a, i32 2
66+
%vecext3 = extractelement <4 x float> %a, i32 3
67+
%add4 = fadd float %vecext2, %vecext3
68+
%vecinit5 = insertelement <4 x float> %vecinit, float %add4, i32 1
69+
%vecext6 = extractelement <4 x float> %b, i32 0
70+
%vecext7 = extractelement <4 x float> %b, i32 1
71+
%add8 = fadd float %vecext6, %vecext7
72+
%vecinit9 = insertelement <4 x float> %vecinit5, float %add8, i32 2
73+
%vecext10 = extractelement <4 x float> %b, i32 2
74+
%vecext11 = extractelement <4 x float> %b, i32 3
75+
%add12 = fadd float %vecext10, %vecext11
76+
%vecinit13 = insertelement <4 x float> %vecinit9, float %add12, i32 3
77+
%shuffle = shufflevector <4 x float> %vecinit13, <4 x float> %a, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
78+
ret <4 x float> %shuffle
79+
}
80+
81+
define <8 x float> @hadd_reverse_v8f32(<8 x float> %a, <8 x float> %b) #0 {
82+
; CHECK-LABEL: @hadd_reverse_v8f32(
83+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A:%.*]], <8 x float> [[B:%.*]], <8 x i32> <i32 7, i32 5, i32 15, i32 13, i32 3, i32 1, i32 11, i32 9>
84+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x float> [[A]], <8 x float> [[B]], <8 x i32> <i32 6, i32 4, i32 14, i32 12, i32 2, i32 0, i32 10, i32 8>
85+
; CHECK-NEXT: [[TMP3:%.*]] = fadd <8 x float> [[TMP1]], [[TMP2]]
86+
; CHECK-NEXT: ret <8 x float> [[TMP3]]
87+
;
88+
%shuffle = shufflevector <8 x float> %a, <8 x float> %a, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
89+
%shuffle1 = shufflevector <8 x float> %b, <8 x float> %b, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
90+
%vecext = extractelement <8 x float> %shuffle, i32 0
91+
%vecext2 = extractelement <8 x float> %shuffle, i32 1
92+
%add = fadd float %vecext, %vecext2
93+
%vecinit = insertelement <8 x float> undef, float %add, i32 0
94+
%vecext3 = extractelement <8 x float> %shuffle, i32 2
95+
%vecext4 = extractelement <8 x float> %shuffle, i32 3
96+
%add5 = fadd float %vecext3, %vecext4
97+
%vecinit6 = insertelement <8 x float> %vecinit, float %add5, i32 1
98+
%vecext7 = extractelement <8 x float> %shuffle1, i32 0
99+
%vecext8 = extractelement <8 x float> %shuffle1, i32 1
100+
%add9 = fadd float %vecext7, %vecext8
101+
%vecinit10 = insertelement <8 x float> %vecinit6, float %add9, i32 2
102+
%vecext11 = extractelement <8 x float> %shuffle1, i32 2
103+
%vecext12 = extractelement <8 x float> %shuffle1, i32 3
104+
%add13 = fadd float %vecext11, %vecext12
105+
%vecinit14 = insertelement <8 x float> %vecinit10, float %add13, i32 3
106+
%vecext15 = extractelement <8 x float> %shuffle, i32 4
107+
%vecext16 = extractelement <8 x float> %shuffle, i32 5
108+
%add17 = fadd float %vecext15, %vecext16
109+
%vecinit18 = insertelement <8 x float> %vecinit14, float %add17, i32 4
110+
%vecext19 = extractelement <8 x float> %shuffle, i32 6
111+
%vecext20 = extractelement <8 x float> %shuffle, i32 7
112+
%add21 = fadd float %vecext19, %vecext20
113+
%vecinit22 = insertelement <8 x float> %vecinit18, float %add21, i32 5
114+
%vecext23 = extractelement <8 x float> %shuffle1, i32 4
115+
%vecext24 = extractelement <8 x float> %shuffle1, i32 5
116+
%add25 = fadd float %vecext23, %vecext24
117+
%vecinit26 = insertelement <8 x float> %vecinit22, float %add25, i32 6
118+
%vecext27 = extractelement <8 x float> %shuffle1, i32 6
119+
%vecext28 = extractelement <8 x float> %shuffle1, i32 7
120+
%add29 = fadd float %vecext27, %vecext28
121+
%vecinit30 = insertelement <8 x float> %vecinit26, float %add29, i32 7
122+
ret <8 x float> %vecinit30
123+
}
124+
125+
define <8 x float> @reverse_hadd_v8f32(<8 x float> %a, <8 x float> %b) #0 {
126+
; CHECK-LABEL: @reverse_hadd_v8f32(
127+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A:%.*]], <8 x float> [[B:%.*]], <8 x i32> <i32 0, i32 2, i32 8, i32 10, i32 4, i32 6, i32 12, i32 14>
128+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x float> [[A]], <8 x float> [[B]], <8 x i32> <i32 1, i32 3, i32 9, i32 11, i32 5, i32 7, i32 13, i32 15>
129+
; CHECK-NEXT: [[TMP3:%.*]] = fadd <8 x float> [[TMP1]], [[TMP2]]
130+
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <8 x float> [[TMP3]], <8 x float> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
131+
; CHECK-NEXT: ret <8 x float> [[SHUFFLE]]
132+
;
133+
%vecext = extractelement <8 x float> %a, i32 0
134+
%vecext1 = extractelement <8 x float> %a, i32 1
135+
%add = fadd float %vecext, %vecext1
136+
%vecinit = insertelement <8 x float> undef, float %add, i32 0
137+
%vecext2 = extractelement <8 x float> %a, i32 2
138+
%vecext3 = extractelement <8 x float> %a, i32 3
139+
%add4 = fadd float %vecext2, %vecext3
140+
%vecinit5 = insertelement <8 x float> %vecinit, float %add4, i32 1
141+
%vecext6 = extractelement <8 x float> %b, i32 0
142+
%vecext7 = extractelement <8 x float> %b, i32 1
143+
%add8 = fadd float %vecext6, %vecext7
144+
%vecinit9 = insertelement <8 x float> %vecinit5, float %add8, i32 2
145+
%vecext10 = extractelement <8 x float> %b, i32 2
146+
%vecext11 = extractelement <8 x float> %b, i32 3
147+
%add12 = fadd float %vecext10, %vecext11
148+
%vecinit13 = insertelement <8 x float> %vecinit9, float %add12, i32 3
149+
%vecext14 = extractelement <8 x float> %a, i32 4
150+
%vecext15 = extractelement <8 x float> %a, i32 5
151+
%add16 = fadd float %vecext14, %vecext15
152+
%vecinit17 = insertelement <8 x float> %vecinit13, float %add16, i32 4
153+
%vecext18 = extractelement <8 x float> %a, i32 6
154+
%vecext19 = extractelement <8 x float> %a, i32 7
155+
%add20 = fadd float %vecext18, %vecext19
156+
%vecinit21 = insertelement <8 x float> %vecinit17, float %add20, i32 5
157+
%vecext22 = extractelement <8 x float> %b, i32 4
158+
%vecext23 = extractelement <8 x float> %b, i32 5
159+
%add24 = fadd float %vecext22, %vecext23
160+
%vecinit25 = insertelement <8 x float> %vecinit21, float %add24, i32 6
161+
%vecext26 = extractelement <8 x float> %b, i32 6
162+
%vecext27 = extractelement <8 x float> %b, i32 7
163+
%add28 = fadd float %vecext26, %vecext27
164+
%vecinit29 = insertelement <8 x float> %vecinit25, float %add28, i32 7
165+
%shuffle = shufflevector <8 x float> %vecinit29, <8 x float> %a, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
166+
ret <8 x float> %shuffle
167+
}
168+
169+
attributes #0 = { "min-legal-vector-width"="128" "target-cpu"="btver2" "target-features"="+avx,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+sse4a,+ssse3" }

0 commit comments

Comments
 (0)