Skip to content

Commit a61835c

Browse files
committed
[CIR][CIRGen][Builtin][X86] Lower shuf*/pshufh* intrinsics
1 parent 822684e commit a61835c

File tree

7 files changed

+232
-6
lines changed

7 files changed

+232
-6
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,55 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
10711071
}
10721072
case X86::BI__builtin_ia32_pshuflw:
10731073
case X86::BI__builtin_ia32_pshuflw256:
1074-
case X86::BI__builtin_ia32_pshuflw512:
1075-
llvm_unreachable("pshuflw NYI");
1074+
case X86::BI__builtin_ia32_pshuflw512: {
1075+
1076+
unsigned imm =
1077+
Ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1078+
auto Ty = cast<cir::VectorType>(Ops[0].getType());
1079+
unsigned numElts = Ty.getSize();
1080+
1081+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1082+
imm = (imm & 0xff) * 0x01010101;
1083+
1084+
int64_t indices[32];
1085+
for (unsigned l = 0; l != numElts; l += 8) {
1086+
for (unsigned i = 0; i != 4; ++i) {
1087+
indices[l + i] = l + (imm & 3);
1088+
imm >>= 2;
1089+
}
1090+
for (unsigned i = 4; i != 8; ++i)
1091+
indices[l + i] = l + i;
1092+
}
1093+
1094+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0],
1095+
ArrayRef(indices, numElts));
1096+
}
10761097
case X86::BI__builtin_ia32_pshufhw:
10771098
case X86::BI__builtin_ia32_pshufhw256:
1078-
case X86::BI__builtin_ia32_pshufhw512:
1079-
llvm_unreachable("pshufhw NYI");
1099+
case X86::BI__builtin_ia32_pshufhw512: {
1100+
1101+
unsigned imm =
1102+
Ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1103+
auto ty = cast<cir::VectorType>(Ops[0].getType());
1104+
unsigned numElts = ty.getSize();
1105+
1106+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1107+
imm = (imm & 0xff) * 0x01010101;
1108+
1109+
int64_t indices[32];
1110+
for (unsigned l = 0; l != numElts; l += 8) {
1111+
for (unsigned i = 0; i != 4; ++i)
1112+
indices[l + i] = l + i;
1113+
for (unsigned i = 4; i != 8; ++i) {
1114+
indices[l + i] = l + 4 + (imm & 3);
1115+
imm >>= 2;
1116+
}
1117+
}
1118+
1119+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0],
1120+
ArrayRef(indices, numElts));
1121+
}
1122+
10801123
case X86::BI__builtin_ia32_pshufd:
10811124
case X86::BI__builtin_ia32_pshufd256:
10821125
case X86::BI__builtin_ia32_pshufd512:
@@ -1111,8 +1154,31 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
11111154
case X86::BI__builtin_ia32_shufpd512:
11121155
case X86::BI__builtin_ia32_shufps:
11131156
case X86::BI__builtin_ia32_shufps256:
1114-
case X86::BI__builtin_ia32_shufps512:
1115-
llvm_unreachable("shufpd NYI");
1157+
case X86::BI__builtin_ia32_shufps512: {
1158+
unsigned imm =
1159+
Ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1160+
auto ty = cast<cir::VectorType>(Ops[0].getType());
1161+
unsigned numElts = ty.getSize();
1162+
unsigned numLanes = CGM.getDataLayout().getTypeSizeInBits(ty) / 128;
1163+
unsigned numLaneElts = numElts / numLanes;
1164+
1165+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1166+
imm = (imm & 0xff) * 0x01010101;
1167+
1168+
int64_t indices[16];
1169+
for (unsigned l = 0; l != numElts; l += numLaneElts) {
1170+
for (unsigned i = 0; i != numLaneElts; ++i) {
1171+
unsigned index = imm % numLaneElts;
1172+
imm /= numLaneElts;
1173+
if (i >= (numLaneElts / 2))
1174+
index += numElts;
1175+
indices[l + i] = l + index;
1176+
}
1177+
}
1178+
1179+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0], Ops[1],
1180+
ArrayRef(indices, numElts));
1181+
}
11161182
case X86::BI__builtin_ia32_permdi256:
11171183
case X86::BI__builtin_ia32_permdf256:
11181184
case X86::BI__builtin_ia32_permdi512:

clang/test/CIR/CodeGen/X86/avx-builtins.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,28 @@ __m256i test_mm256_insertf128_si256(__m256i A, __m128i B) {
205205
// LLVM: shufflevector <8 x i32> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
206206
return _mm256_insertf128_si256(A, B, 0);
207207
}
208+
209+
__m256d test_mm256_shuffle_pd(__m256d A, __m256d B) {
210+
// CIR-LABEL: test_mm256_shuffle_pd
211+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 4>) [#cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<2> : !s32i, #cir.int<6> : !s32i] : !cir.vector<!cir.double x 4>
212+
213+
// CHECK-LABEL: test_mm256_shuffle_pd
214+
// CHECK: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
215+
216+
// OGCG-LABEL: test_mm256_shuffle_pd
217+
// OGCG: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
218+
return _mm256_shuffle_pd(A, B, 0);
219+
}
220+
221+
__m256 test_mm256_shuffle_ps(__m256 A, __m256 B) {
222+
// CIR-LABEL: test_mm256_shuffle_ps
223+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 8>) [#cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<8> : !s32i, #cir.int<8> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<12> : !s32i, #cir.int<12> : !s32i] : !cir.vector<!cir.float x 8>
224+
225+
// CHECK-LABEL: test_mm256_shuffle_ps
226+
// CHECK: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 0, i32 8, i32 8, i32 4, i32 4, i32 12, i32 12>
227+
228+
// OGCG-LABEL: test_mm256_shuffle_ps
229+
// OGCG: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 0, i32 8, i32 8, i32 4, i32 4, i32 12, i32 12>
230+
return _mm256_shuffle_ps(A, B, 0);
231+
}
232+

clang/test/CIR/CodeGen/X86/avx2-builtins.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,26 @@ __m256i test2_mm256_inserti128_si256(__m256i a, __m128i b) {
108108
return _mm256_inserti128_si256(a, b, 0);
109109
}
110110

111+
__m256i test_mm256_shufflelo_epi16(__m256i a) {
112+
// CIR-LABEL: _mm256_shufflelo_epi16
113+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 16>) [#cir.int<3> : !s32i, #cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<1> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i, #cir.int<11> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<9> : !s32i, #cir.int<12> : !s32i, #cir.int<13> : !s32i, #cir.int<14> : !s32i, #cir.int<15> : !s32i] : !cir.vector<!s16i x 16>
111114

115+
// LLVM-LABEL: test_mm256_shufflelo_epi16
116+
// LLVM: shufflevector <16 x i16> %{{.*}}, <16 x i16> poison, <16 x i32> <i32 3, i32 0, i32 1, i32 1, i32 4, i32 5, i32 6, i32 7, i32 11, i32 8, i32 9, i32 9, i32 12, i32 13, i32 14, i32 15>
112117

118+
// OGCG-LABEL: test_mm256_shufflelo_epi16
119+
// OGCG: shufflevector <16 x i16> %{{.*}}, <16 x i16> poison, <16 x i32> <i32 3, i32 0, i32 1, i32 1, i32 4, i32 5, i32 6, i32 7, i32 11, i32 8, i32 9, i32 9, i32 12, i32 13, i32 14, i32 15>
120+
return _mm256_shufflelo_epi16(a, 83);
121+
}
122+
123+
__m256i test_mm256_shufflehi_epi16(__m256i a) {
124+
// CIR-LABEL: _mm256_shufflehi_epi16
125+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 16>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<7> : !s32i, #cir.int<6> : !s32i, #cir.int<6> : !s32i, #cir.int<5> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<15> : !s32i, #cir.int<14> : !s32i, #cir.int<14> : !s32i, #cir.int<13> : !s32i] : !cir.vector<!s16i x 16>
126+
127+
// LLVM-LABEL: test_mm256_shufflehi_epi16
128+
// LLVM: shufflevector <16 x i16> %{{.*}}, <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 7, i32 6, i32 6, i32 5, i32 8, i32 9, i32 10, i32 11, i32 15, i32 14, i32 14, i32 13>
129+
130+
// OGCG-LABEL: test_mm256_shufflehi_epi16
131+
// OGCG: shufflevector <16 x i16> %{{.*}}, <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 7, i32 6, i32 6, i32 5, i32 8, i32 9, i32 10, i32 11, i32 15, i32 14, i32 14, i32 13>
132+
return _mm256_shufflehi_epi16(a, 107);
133+
}

clang/test/CIR/CodeGen/X86/avx512bw-builtins.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512bw -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion
99
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
1010

11+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
12+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -fno-signed-char -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
13+
1114
#include <immintrin.h>
1215

1316
void test_mm512_mask_storeu_epi16(void *__P, __mmask32 __U, __m512i __A) {
@@ -73,3 +76,27 @@ __m512i test_mm512_maskz_loadu_epi8(__mmask64 __U, void const *__P) {
7376
// LLVM: @llvm.masked.load.v64i8.p0(ptr %{{.*}}, i32 1, <64 x i1> %{{.*}}, <64 x i8> %{{.*}})
7477
return _mm512_maskz_loadu_epi8(__U, __P);
7578
}
79+
80+
__m512i test_mm512_shufflelo_epi16(__m512i __A) {
81+
// CIR-LABEL: _mm512_shufflelo_epi16
82+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 32>) [#cir.int<1> : !s32i, #cir.int<1> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i, #cir.int<9> : !s32i, #cir.int<9> : !s32i, #cir.int<8> : !s32i, #cir.int<8> : !s32i, #cir.int<12> : !s32i, #cir.int<13> : !s32i, #cir.int<14> : !s32i, #cir.int<15> : !s32i, #cir.int<17> : !s32i, #cir.int<17> : !s32i, #cir.int<16> : !s32i, #cir.int<16> : !s32i, #cir.int<20> : !s32i, #cir.int<21> : !s32i, #cir.int<22> : !s32i, #cir.int<23> : !s32i, #cir.int<25> : !s32i, #cir.int<25> : !s32i, #cir.int<24> : !s32i, #cir.int<24> : !s32i, #cir.int<28> : !s32i, #cir.int<29> : !s32i, #cir.int<30> : !s32i, #cir.int<31> : !s32i] : !cir.vector<!s16i x 32>
83+
84+
// LLVM-LABEL: @test_mm512_shufflelo_epi16
85+
// LLVM: shufflevector <32 x i16> %{{.*}}, <32 x i16> poison, <32 x i32> <i32 1, i32 1, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7, i32 9, i32 9, i32 8, i32 8, i32 12, i32 13, i32 14, i32 15, i32 17, i32 17, i32 16, i32 16, i32 20, i32 21, i32 22, i32 23, i32 25, i32 25, i32 24, i32 24, i32 28, i32 29, i32 30, i32 31>
86+
87+
// OGCG-LABEL: @test_mm512_shufflelo_epi16
88+
// OGCG: shufflevector <32 x i16> %{{.*}}, <32 x i16> poison, <32 x i32> <i32 1, i32 1, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7, i32 9, i32 9, i32 8, i32 8, i32 12, i32 13, i32 14, i32 15, i32 17, i32 17, i32 16, i32 16, i32 20, i32 21, i32 22, i32 23, i32 25, i32 25, i32 24, i32 24, i32 28, i32 29, i32 30, i32 31>
89+
return _mm512_shufflelo_epi16(__A, 5);
90+
}
91+
92+
__m512i test_mm512_shufflehi_epi16(__m512i __A) {
93+
// CIR-LABEL: _mm512_shufflehi_epi16
94+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 32>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<5> : !s32i, #cir.int<5> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<13> : !s32i, #cir.int<13> : !s32i, #cir.int<12> : !s32i, #cir.int<12> : !s32i, #cir.int<16> : !s32i, #cir.int<17> : !s32i, #cir.int<18> : !s32i, #cir.int<19> : !s32i, #cir.int<21> : !s32i, #cir.int<21> : !s32i, #cir.int<20> : !s32i, #cir.int<20> : !s32i, #cir.int<24> : !s32i, #cir.int<25> : !s32i, #cir.int<26> : !s32i, #cir.int<27> : !s32i, #cir.int<29> : !s32i, #cir.int<29> : !s32i, #cir.int<28> : !s32i, #cir.int<28> : !s32i] : !cir.vector<!s16i x 32>
95+
96+
// LLVM-LABEL: @test_mm512_shufflehi_epi16
97+
// LLVM: shufflevector <32 x i16> %{{.*}}, <32 x i16> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 5, i32 4, i32 4, i32 8, i32 9, i32 10, i32 11, i32 13, i32 13, i32 12, i32 12, i32 16, i32 17, i32 18, i32 19, i32 21, i32 21, i32 20, i32 20, i32 24, i32 25, i32 26, i32 27, i32 29, i32 29, i32 28, i32 28>
98+
99+
// OGCG-LABEL: @test_mm512_shufflehi_epi16
100+
// OGCG: shufflevector <32 x i16> %{{.*}}, <32 x i16> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 5, i32 4, i32 4, i32 8, i32 9, i32 10, i32 11, i32 13, i32 13, i32 12, i32 12, i32 16, i32 17, i32 18, i32 19, i32 21, i32 21, i32 20, i32 20, i32 24, i32 25, i32 26, i32 27, i32 29, i32 29, i32 28, i32 28>
101+
return _mm512_shufflehi_epi16(__A, 5);
102+
}

clang/test/CIR/CodeGen/X86/avx512f-builtins.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion
99
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
1010

11+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
12+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
13+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
14+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG
15+
1116
#include <immintrin.h>
1217

1318
__m512 test_mm512_undefined(void) {
@@ -670,3 +675,28 @@ __m512i test_mm512_inserti32x4(__m512i __A, __m128i __B) {
670675
// LLVM: shufflevector <16 x i32> %{{.*}}, <16 x i32> %{{.*}}, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 16, i32 17, i32 18, i32 19, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
671676
return _mm512_inserti32x4(__A, __B, 1);
672677
}
678+
679+
__m512d test_mm512_shuffle_pd(__m512d __M, __m512d __V) {
680+
// CIR-LABEL: test_mm512_shuffle_pd
681+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 8>) [#cir.int<0> : !s32i, #cir.int<8> : !s32i, #cir.int<3> : !s32i, #cir.int<10> : !s32i, #cir.int<4> : !s32i, #cir.int<12> : !s32i, #cir.int<6> : !s32i, #cir.int<14> : !s32i] : !cir.vector<!cir.double x 8>
682+
683+
// CHECK-LABEL: test_mm512_shuffle_pd
684+
// CHECK: shufflevector <8 x double> %{{.*}}, <8 x double> %{{.*}}, <8 x i32> <i32 0, i32 8, i32 3, i32 10, i32 4, i32 12, i32 6, i32 14>
685+
686+
// OGCG-LABEL: test_mm512_shuffle_pd
687+
// OGCG: shufflevector <8 x double> %{{.*}}, <8 x double> %{{.*}}, <8 x i32> <i32 0, i32 8, i32 3, i32 10, i32 4, i32 12, i32 6, i32 14>
688+
return _mm512_shuffle_pd(__M, __V, 4);
689+
}
690+
691+
__m512 test_mm512_shuffle_ps(__m512 __M, __m512 __V) {
692+
// CIR-LABEL: test_mm512_shuffle_ps
693+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 16>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<16> : !s32i, #cir.int<16> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<20> : !s32i, #cir.int<20> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<24> : !s32i, #cir.int<24> : !s32i, #cir.int<12> : !s32i, #cir.int<13> : !s32i, #cir.int<28> : !s32i, #cir.int<28> : !s32i] : !cir.vector<!cir.float x 16>
694+
695+
// CHECK-LABEL: test_mm512_shuffle_ps
696+
// CHECK: shufflevector <16 x float> %{{.*}}, <16 x float> %{{.*}}, <16 x i32> <i32 0, i32 1, i32 16, i32 16, i32 4, i32 5, i32 20, i32 20, i32 8, i32 9, i32 24, i32 24, i32 12, i32 13, i32 28, i32 28>
697+
698+
// OGCG-LABEL: test_mm512_shuffle_ps
699+
// OGCG: shufflevector <16 x float> %{{.*}}, <16 x float> %{{.*}}, <16 x i32> <i32 0, i32 1, i32 16, i32 16, i32 4, i32 5, i32 20, i32 20, i32 8, i32 9, i32 24, i32 24, i32 12, i32 13, i32 28, i32 28>
700+
return _mm512_shuffle_ps(__M, __V, 4);
701+
}
702+

clang/test/CIR/CodeGen/X86/sse-builtins.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse -fclangir -emit-llvm -o %t.ll -Wall -Werror
99
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
1010

11+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
12+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
13+
1114
// This test mimics clang/test/CodeGen/X86/sse-builtins.c, which eventually
1215
// CIR shall be able to support fully.
1316

@@ -65,3 +68,14 @@ unsigned int test_mm_getcsr(void) {
6568
return _mm_getcsr();
6669
}
6770

71+
__m128 test_mm_shuffle_ps(__m128 A, __m128 B) {
72+
// CIR-LABEL: _mm_shuffle_ps
73+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 4>) [#cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i] : !cir.vector<!cir.float x 4>
74+
75+
// CHECK-LABEL: test_mm_shuffle_ps
76+
// CHECK: shufflevector <4 x float> {{.*}}, <4 x float> {{.*}}, <4 x i32> <i32 0, i32 0, i32 4, i32 4>
77+
78+
// OGCG-LABEL: test_mm_shuffle_ps
79+
// OGCG: shufflevector <4 x float> {{.*}}, <4 x float> {{.*}}, <4 x i32> <i32 0, i32 0, i32 4, i32 4>
80+
return _mm_shuffle_ps(A, B, 0);
81+
}

clang/test/CIR/CodeGen/X86/sse2-builtins.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
99
// RUN: FileCheck --check-prefixes=LLVM-CHECK,LLVM-X64 --input-file=%t.ll %s
1010

11+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
12+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
13+
14+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
15+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
16+
1117
// This test mimics clang/test/CodeGen/X86/sse2-builtins.c, which eventually
1218
// CIR shall be able to support fully.
1319

@@ -74,3 +80,40 @@ void test_mm_mfence(void) {
7480
// CIR-CHECK: {{%.*}} = cir.llvm.intrinsic "x86.sse2.mfence" : () -> !void
7581
// LLVM-CHECK: call void @llvm.x86.sse2.mfence()
7682
}
83+
84+
__m128i test_mm_shufflelo_epi16(__m128i A) {
85+
// CIR-LABEL: _mm_shufflelo_epi16
86+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 8>) [#cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!s16i x 8>
87+
88+
// LLVM-LABEL: test_mm_shufflelo_epi16
89+
// LLVM: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7>
90+
91+
// OGCG-LABEL: test_mm_shufflelo_epi16
92+
// OGCG: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7>
93+
return _mm_shufflelo_epi16(A, 0);
94+
}
95+
96+
__m128i test_mm_shufflehi_epi16(__m128i A) {
97+
// CIR-LABEL: _mm_shufflehi_epi16
98+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s16i x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i] : !cir.vector<!s16i x 8>
99+
100+
// LLVM-LABEL: test_mm_shufflehi_epi16
101+
// LLVM: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 4, i32 4, i32 4>
102+
103+
// OGCG-LABEL: test_mm_shufflehi_epi16
104+
// OGCG: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 4, i32 4, i32 4>
105+
return _mm_shufflehi_epi16(A, 0);
106+
}
107+
108+
__m128d test_mm_shuffle_pd(__m128d A, __m128d B) {
109+
// CIR-LABEL: test_mm_shuffle_pd
110+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 2>) [#cir.int<1> : !s32i, #cir.int<2> : !s32i] : !cir.vector<!cir.double x 2>
111+
112+
// CHECK-LABEL: test_mm_shuffle_pd
113+
// CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 1, i32 2>
114+
115+
// OGCG-LABEL: test_mm_shuffle_pd
116+
// OGCG: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 1, i32 2>
117+
return _mm_shuffle_pd(A, B, 1);
118+
}
119+

0 commit comments

Comments
 (0)