Skip to content

Commit 11b3ee0

Browse files
authored
[CIR][CIRGen][Builtin][X86] Lower shuf*/pshufh* intrinsics (#1896)
1 parent 4914dc7 commit 11b3ee0

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
@@ -1164,12 +1164,55 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
11641164
}
11651165
case X86::BI__builtin_ia32_pshuflw:
11661166
case X86::BI__builtin_ia32_pshuflw256:
1167-
case X86::BI__builtin_ia32_pshuflw512:
1168-
llvm_unreachable("pshuflw NYI");
1167+
case X86::BI__builtin_ia32_pshuflw512: {
1168+
1169+
unsigned imm =
1170+
Ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1171+
auto Ty = cast<cir::VectorType>(Ops[0].getType());
1172+
unsigned numElts = Ty.getSize();
1173+
1174+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1175+
imm = (imm & 0xff) * 0x01010101;
1176+
1177+
int64_t indices[32];
1178+
for (unsigned l = 0; l != numElts; l += 8) {
1179+
for (unsigned i = 0; i != 4; ++i) {
1180+
indices[l + i] = l + (imm & 3);
1181+
imm >>= 2;
1182+
}
1183+
for (unsigned i = 4; i != 8; ++i)
1184+
indices[l + i] = l + i;
1185+
}
1186+
1187+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0],
1188+
ArrayRef(indices, numElts));
1189+
}
11691190
case X86::BI__builtin_ia32_pshufhw:
11701191
case X86::BI__builtin_ia32_pshufhw256:
1171-
case X86::BI__builtin_ia32_pshufhw512:
1172-
llvm_unreachable("pshufhw NYI");
1192+
case X86::BI__builtin_ia32_pshufhw512: {
1193+
1194+
unsigned imm =
1195+
Ops[1].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1196+
auto ty = cast<cir::VectorType>(Ops[0].getType());
1197+
unsigned numElts = ty.getSize();
1198+
1199+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1200+
imm = (imm & 0xff) * 0x01010101;
1201+
1202+
int64_t indices[32];
1203+
for (unsigned l = 0; l != numElts; l += 8) {
1204+
for (unsigned i = 0; i != 4; ++i)
1205+
indices[l + i] = l + i;
1206+
for (unsigned i = 4; i != 8; ++i) {
1207+
indices[l + i] = l + 4 + (imm & 3);
1208+
imm >>= 2;
1209+
}
1210+
}
1211+
1212+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0],
1213+
ArrayRef(indices, numElts));
1214+
}
1215+
11731216
case X86::BI__builtin_ia32_pshufd:
11741217
case X86::BI__builtin_ia32_pshufd256:
11751218
case X86::BI__builtin_ia32_pshufd512:
@@ -1204,8 +1247,31 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
12041247
case X86::BI__builtin_ia32_shufpd512:
12051248
case X86::BI__builtin_ia32_shufps:
12061249
case X86::BI__builtin_ia32_shufps256:
1207-
case X86::BI__builtin_ia32_shufps512:
1208-
llvm_unreachable("shufpd NYI");
1250+
case X86::BI__builtin_ia32_shufps512: {
1251+
unsigned imm =
1252+
Ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
1253+
auto ty = cast<cir::VectorType>(Ops[0].getType());
1254+
unsigned numElts = ty.getSize();
1255+
unsigned numLanes = CGM.getDataLayout().getTypeSizeInBits(ty) / 128;
1256+
unsigned numLaneElts = numElts / numLanes;
1257+
1258+
// Splat the 8-bits of immediate 4 times to help the loop wrap around.
1259+
imm = (imm & 0xff) * 0x01010101;
1260+
1261+
int64_t indices[16];
1262+
for (unsigned l = 0; l != numElts; l += numLaneElts) {
1263+
for (unsigned i = 0; i != numLaneElts; ++i) {
1264+
unsigned index = imm % numLaneElts;
1265+
imm /= numLaneElts;
1266+
if (i >= (numLaneElts / 2))
1267+
index += numElts;
1268+
indices[l + i] = l + index;
1269+
}
1270+
}
1271+
1272+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0], Ops[1],
1273+
ArrayRef(indices, numElts));
1274+
}
12091275
case X86::BI__builtin_ia32_permdi256:
12101276
case X86::BI__builtin_ia32_permdf256:
12111277
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
@@ -11,6 +11,9 @@
1111
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512bw -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefix=OGCG
1212
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512bw -fno-signed-char -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefix=OGCG
1313

14+
// 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
15+
// 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
16+
1417
#include <immintrin.h>
1518

1619
void test_mm512_mask_storeu_epi16(void *__P, __mmask32 __U, __m512i __A) {
@@ -104,3 +107,27 @@ __mmask32 test_mm512_movepi16_mask(__m512i __A) {
104107
// OGCG: [[CMP:%.*]] = icmp slt <32 x i16> %{{.*}}, zeroinitializer
105108
return _mm512_movepi16_mask(__A);
106109
}
110+
111+
__m512i test_mm512_shufflelo_epi16(__m512i __A) {
112+
// CIR-LABEL: _mm512_shufflelo_epi16
113+
// 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>
114+
115+
// LLVM-LABEL: @test_mm512_shufflelo_epi16
116+
// 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>
117+
118+
// OGCG-LABEL: @test_mm512_shufflelo_epi16
119+
// 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>
120+
return _mm512_shufflelo_epi16(__A, 5);
121+
}
122+
123+
__m512i test_mm512_shufflehi_epi16(__m512i __A) {
124+
// CIR-LABEL: _mm512_shufflehi_epi16
125+
// 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>
126+
127+
// LLVM-LABEL: @test_mm512_shufflehi_epi16
128+
// 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>
129+
130+
// OGCG-LABEL: @test_mm512_shufflehi_epi16
131+
// 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>
132+
return _mm512_shufflehi_epi16(__A, 5);
133+
}

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)