Skip to content

Commit 90fc6c4

Browse files
authored
[CIR][CIRGen][Builtin][X86] Lower insert* intrinsics (#1829)
Only one thing to note related to the shuffles performed for these intrinsics. We could tackle this in a different PR tho. OG's builder creates unary shuffles by passing a poison value for the second vector operand. ```cpp /// Create a unary shuffle. The second vector operand of the IR instruction /// is poison. Value *CreateShuffleVector(Value *V, ArrayRef<int> Mask, const Twine &Name = “”) { return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name); } ``` In CIR, we currently work around this by duplicating the single vector argument as both operands: ```cpp cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, llvm::ArrayRef<int64_t> mask) { // FIXME(cir): Support use cir.vec.shuffle with single vec // Workaround: pass Vec as both vec1 and vec2 return createVecShuffle(loc, vec1, vec1, mask); } ``` While this is just a minor nit and I don’t believe we provoke a semantic difference, should we revisit the workaround stated in the comment for parity with OG?
1 parent 8923438 commit 90fc6c4

File tree

8 files changed

+308
-3
lines changed

8 files changed

+308
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,39 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
973973
case X86::BI__builtin_ia32_insertf64x2_256:
974974
case X86::BI__builtin_ia32_inserti64x2_256:
975975
case X86::BI__builtin_ia32_insertf64x2_512:
976-
case X86::BI__builtin_ia32_inserti64x2_512:
977-
llvm_unreachable("insertf128 NYI");
976+
case X86::BI__builtin_ia32_inserti64x2_512: {
977+
unsigned dstNumElts = cast<cir::VectorType>(Ops[0].getType()).getSize();
978+
unsigned srcNumElts = cast<cir::VectorType>(Ops[1].getType()).getSize();
979+
unsigned subVectors = dstNumElts / srcNumElts;
980+
unsigned index =
981+
Ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
982+
assert(llvm::isPowerOf2_32(subVectors) && "Expected power of 2 subvectors");
983+
index &= subVectors - 1; // Remove any extra bits.
984+
index *= srcNumElts;
985+
986+
int64_t indices[16];
987+
for (unsigned i = 0; i != dstNumElts; ++i)
988+
indices[i] = (i >= srcNumElts) ? srcNumElts + (i % srcNumElts) : i;
989+
990+
cir::ConstantOp poisonVec =
991+
builder.getConstant(getLoc(E->getExprLoc()),
992+
builder.getAttr<cir::PoisonAttr>(Ops[1].getType()));
993+
994+
mlir::Value op1 =
995+
builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[1], poisonVec,
996+
ArrayRef(indices, dstNumElts));
997+
998+
for (unsigned i = 0; i != dstNumElts; ++i) {
999+
if (i >= index && i < (index + srcNumElts))
1000+
indices[i] = (i - index) + dstNumElts;
1001+
else
1002+
indices[i] = i;
1003+
}
1004+
1005+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0], op1,
1006+
ArrayRef(indices, dstNumElts));
1007+
}
1008+
9781009
case X86::BI__builtin_ia32_pmovqd512_mask:
9791010
case X86::BI__builtin_ia32_pmovwb512_mask:
9801011
llvm_unreachable("pmovqd512_mask NYI");

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,36 @@ __m256 test_mm256_blend_ps(__m256 A, __m256 B) {
172172
// OGCG: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 8, i32 1, i32 10, i32 3, i32 12, i32 13, i32 6, i32 7>
173173
return _mm256_blend_ps(A, B, 0x35);
174174
}
175+
176+
__m256d test_mm256_insertf128_pd(__m256d A, __m128d B) {
177+
// CIR-LABEL: test_mm256_insertf128_pd
178+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 2>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.double x 4>
179+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 4>) [#cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.double x 4>
180+
181+
// LLVM-LABEL: test_mm256_insertf128_pd
182+
// LLVM: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
183+
// LLVM: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
184+
return _mm256_insertf128_pd(A, B, 0);
185+
}
186+
187+
__m256 test_mm256_insertf128_ps(__m256 A, __m128 B) {
188+
// CIR-LABEL: test_mm256_insertf128_ps
189+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.float x 8>
190+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i] : !cir.vector<!cir.float x 8>
191+
192+
// LLVM-LABEL: test_mm256_insertf128_ps
193+
// LLVM: shufflevector <4 x float> %{{.*}}, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
194+
// LLVM: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
195+
return _mm256_insertf128_ps(A, B, 1);
196+
}
197+
198+
__m256i test_mm256_insertf128_si256(__m256i A, __m128i B) {
199+
// CIR-LABEL: test_mm256_insertf128_si256
200+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s32i x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s32i x 8>
201+
// %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s32i x 8>) [#cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i]
202+
203+
// LLVM-LABEL: test_mm256_insertf128_si256
204+
// LLVM: shufflevector <4 x i32> %{{.*}}, <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
205+
// 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>
206+
return _mm256_insertf128_si256(A, B, 0);
207+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: x86-registered-target
3+
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -disable-O0-optnone -fclangir -emit-cir -o %t.cir | opt -S -passes=mem2reg
4+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
5+
6+
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -disable-O0-optnone -fclangir -emit-llvm -o %t.ll | opt -S -passes=mem2reg
7+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
8+
9+
#include <immintrin.h>
10+
11+
// CIR-LABEL: @test_mm256_insertf128_pd_0(
12+
// CIR: [[A:%.*]] = cir.load align(32) %0 : !cir.ptr<!cir.vector<!cir.double x 4>>, !cir.vector<!cir.double x 4>
13+
// CIR: [[B:%.*]] = cir.load align(16) %1 : !cir.ptr<!cir.vector<!cir.double x 2>>, !cir.vector<!cir.double x 2>
14+
// CIR: %{{.*}} = cir.vec.shuffle([[B]], %{{.*}} : !cir.vector<!cir.double x 2>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.double x 4>
15+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle([[A]], %{{.*}} : !s32i, #cir.int<5> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.double x 4>
16+
// CIR: cir.return %{{.*}} : !cir.vector<!cir.double x 4>
17+
18+
19+
// LLVM-LABEL: @test_mm256_insertf128_pd_0
20+
// LLVM: [[A:%.*]] = load <4 x double>, ptr %{{.*}}, align 32
21+
// LLVM: [[B:%.*]] = load <2 x double>, ptr %{{.*}}, align 16
22+
// LLVM-NEXT: [[WIDEN:%.*]] = shufflevector <2 x double> [[B]], <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
23+
// LLVM-NEXT: [[INSERT:%.*]] = shufflevector <4 x double> [[A]], <4 x double> [[WIDEN]], <4 x i32> <i32 4, i32 5, i32 2, i32 3>
24+
// LLVM: ret <4 x double>
25+
__m256d test_mm256_insertf128_pd_0(__m256d a, __m128d b) {
26+
return _mm256_insertf128_pd(a, b, 0);
27+
}
28+
29+
// CIR-LABEL: @test_mm256_insertf128_ps_0(
30+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!cir.float x 8>
31+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 8>) [#cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!cir.float x 8>
32+
// CIR: cir.return %{{.*}} : !cir.vector<!cir.float x 8>
33+
34+
// LLVM-LABEL: @test_mm256_insertf128_ps_0(
35+
// LLVM: %{{.*}} = shufflevector <4 x float> %{{.*}}, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
36+
// LLVM-NEXT: %{{.*}} = shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
37+
// LLVM: ret <8 x float> %{{.*}}
38+
//
39+
__m256 test_mm256_insertf128_ps_0(__m256 a, __m128 b) {
40+
return _mm256_insertf128_ps(a, b, 0);
41+
}
42+
43+
// CIR-LABEL: @test_mm256_insertf128_ps_1(
44+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!cir.float x 8>
45+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i] : !cir.vector<!cir.float x 8>
46+
// CIR: cir.return %{{.*}} : !cir.vector<!cir.float x 8>
47+
48+
// LLVM-LABEL: define dso_local <8 x float> @test_mm256_insertf128_ps_1(
49+
// LLVM: %{{.*}} = shufflevector <4 x float> %{{.*}}, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
50+
// LLVM-NEXT: %{{.*}} = shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
51+
// LLVM: ret <8 x float> %{{.*}}
52+
//
53+
__m256 test_mm256_insertf128_ps_1(__m256 a, __m128 b) {
54+
return _mm256_insertf128_ps(a, b, 1);
55+
}
56+
57+
// CIR-LABEL: @test_mm256_insertf128_si256_0(
58+
// CIR: [[TMP0:%.*]] = cir.cast(bitcast, %{{.*}} : !cir.vector<!s64i x 4>), !cir.vector<!s32i x 8>
59+
// CIR: [[TMP1:%.*]] = cir.cast(bitcast, %{{.*}} : !cir.vector<!s64i x 2>), !cir.vector<!s32i x 4>
60+
// CIR: %{{.*}} = cir.vec.shuffle([[TMP1]], %{{.*}} : !cir.vector<!s32i x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!s32i x 8>
61+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle([[TMP0]], %{{.*}} : !cir.vector<!s32i x 8>) [#cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!s32i x 8>
62+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !cir.vector<!s32i x 8>), !cir.vector<!s64i x 4>
63+
// CIR: cir.return %{{.*}} : !cir.vector<!s64i x 4>
64+
65+
// LLVM-LABEL: @test_mm256_insertf128_si256_0
66+
// LLVM: [[TMP0:%.*]] = bitcast <4 x i64> %{{.*}} to <8 x i32>
67+
// LLVM: [[TMP1:%.*]] = bitcast <2 x i64> %{{.*}} to <4 x i32>
68+
// LLVM: [[WIDEN:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
69+
// LLVM-NEXT: [[INSERT:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> [[WIDEN]], <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
70+
// LLVM: [[TMP2:%.*]] = bitcast <8 x i32> [[INSERT]] to <4 x i64>
71+
// LLVM: ret <4 x i64> %{{.*}}
72+
//
73+
__m256i test_mm256_insertf128_si256_0(__m256i a, __m128i b) {
74+
return _mm256_insertf128_si256(a, b, 0);
75+
}
76+
77+
// CIR-LABEL: @test_mm256_insertf128_si256_1(
78+
// CIR: [[TMP0:%.*]] = cir.cast(bitcast, %{{.*}} : !cir.vector<!s64i x 4>), !cir.vector<!s32i x 8>
79+
// CIR: [[TMP1:%.*]] = cir.cast(bitcast, %{{.*}} : !cir.vector<!s64i x 2>), !cir.vector<!s32i x 4>
80+
// CIR: %{{.*}} = cir.vec.shuffle([[TMP1]], %{{.*}} : !cir.vector<!s32i x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!s32i x 8>
81+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle([[TMP0]], %{{.*}} : !cir.vector<!s32i x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i] : !cir.vector<!s32i x 8>
82+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !cir.vector<!s32i x 8>), !cir.vector<!s64i x 4>
83+
// CIR: cir.return %{{.*}} : !cir.vector<!s64i x 4>
84+
85+
// LLVM-LABEL: @test_mm256_insertf128_si256_1
86+
// LLVM: [[TMP0:%.*]] = bitcast <4 x i64> %{{.*}} to <8 x i32>
87+
// LLVM: [[TMP1:%.*]] = bitcast <2 x i64> %{{.*}} to <4 x i32>
88+
// LLVM: [[WIDEN:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
89+
// LLVM-NEXT: [[INSERT:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> [[WIDEN]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
90+
// LLVM: [[TMP2:%.*]] = bitcast <8 x i32> [[INSERT]] to <4 x i64>
91+
// LLVM: ret <4 x i64> %{{.*}}
92+
//
93+
__m256i test_mm256_insertf128_si256_1(__m256i a, __m128i b) {
94+
return _mm256_insertf128_si256(a, b, 1);
95+
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,42 @@ __m256i test_mm256_blend_epi32(__m256i a, __m256i b) {
7171
// OGCG-NOT: @llvm.x86.avx2.pblendd.256
7272
// OGCG: shufflevector <8 x i32> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> <i32 8, i32 1, i32 10, i32 3, i32 12, i32 13, i32 6, i32 7>
7373
return _mm256_blend_epi32(a, b, 0x35);
74-
}
74+
}
75+
76+
__m256i test0_mm256_inserti128_si256(__m256i a, __m128i b) {
77+
78+
// CIR-LABEL: test0_mm256_inserti128_si256
79+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 2>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s64i x 4>
80+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 4>) [#cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s64i x 4>
81+
82+
// LLVM-LABEL: test0_mm256_inserti128_si256
83+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
84+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
85+
return _mm256_inserti128_si256(a, b, 0);
86+
}
87+
88+
__m256i test1_mm256_inserti128_si256(__m256i a, __m128i b) {
89+
// CIR-LABEL: test1_mm256_inserti128_si256
90+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 2>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s64i x 4>
91+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 4>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i] : !cir.vector<!s64i x 4>
92+
93+
// LLVM-LABEL: test1_mm256_inserti128_si256
94+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
95+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
96+
return _mm256_inserti128_si256(a, b, 1);
97+
}
98+
99+
// Immediate should be truncated to one bit.
100+
__m256i test2_mm256_inserti128_si256(__m256i a, __m128i b) {
101+
// CIR-LABEL: test2_mm256_inserti128_si256
102+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 2>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s64i x 4>
103+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 4>) [#cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!s64i x 4>
104+
105+
// LLVM-LABEL: test2_mm256_inserti128_si256
106+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
107+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
108+
return _mm256_inserti128_si256(a, b, 0);
109+
}
110+
111+
112+

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,39 @@ __m512i test_mm512_movm_epi64(__mmask8 __A) {
1414
// LLVM: %{{.*}} = sext <8 x i1> %{{.*}} to <8 x i64>
1515
return _mm512_movm_epi64(__A);
1616
}
17+
18+
__m512 test_mm512_insertf32x8(__m512 __A, __m256 __B) {
19+
// CIR-LABEL: test_mm512_insertf32x8
20+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.float x 16>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i, #cir.int<16> : !s32i, #cir.int<17> : !s32i, #cir.int<18> : !s32i, #cir.int<19> : !s32i, #cir.int<20> : !s32i, #cir.int<21> : !s32i, #cir.int<22> : !s32i, #cir.int<23> : !s32i] : !cir.vector<!cir.float x 16>
21+
22+
// LLVM-LABEL: @test_mm512_insertf32x8
23+
// LLVM: shufflevector <16 x float> %{{.*}}, <16 x float> %{{.*}}, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23>
24+
return _mm512_insertf32x8(__A, __B, 1);
25+
}
26+
27+
__m512i test_mm512_inserti32x8(__m512i __A, __m256i __B) {
28+
// CIR-LABEL: test_mm512_inserti32x8
29+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s32i x 16>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i, #cir.int<16> : !s32i, #cir.int<17> : !s32i, #cir.int<18> : !s32i, #cir.int<19> : !s32i, #cir.int<20> : !s32i, #cir.int<21> : !s32i, #cir.int<22> : !s32i, #cir.int<23> : !s32i] : !cir.vector<!s32i x 16>
30+
31+
// LLVM-LABEL: @test_mm512_inserti32x8
32+
// LLVM: shufflevector <16 x i32> %{{.*}}, <16 x i32> %{{.*}}, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23>
33+
return _mm512_inserti32x8(__A, __B, 1);
34+
}
35+
36+
__m512d test_mm512_insertf64x2(__m512d __A, __m128d __B) {
37+
// CIR-LABEL: test_mm512_insertf64x2
38+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.double x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i] : !cir.vector<!cir.double x 8>
39+
40+
// LLVM-LABEL: @test_mm512_insertf64x2
41+
// LLVM: shufflevector <8 x double> %{{.*}}, <8 x double> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 9>
42+
return _mm512_insertf64x2(__A, __B, 3);
43+
}
44+
45+
__m512i test_mm512_inserti64x2(__m512i __A, __m128i __B) {
46+
// CIR-LABEL: test_mm512_inserti64x2
47+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!s64i x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<!s64i x 8>
48+
49+
// LLVM-LABEL: @test_mm512_inserti64x2
50+
// LLVM: shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 8, i32 9, i32 4, i32 5, i32 6, i32 7>
51+
return _mm512_inserti64x2(__A, __B, 1);
52+
}

0 commit comments

Comments
 (0)