Skip to content

Commit 4822efe

Browse files
committed
[CIR][CIRGen][Builtin][X86] Lower insert* intrinsics
1 parent 34c12ae commit 4822efe

File tree

8 files changed

+319
-3
lines changed

8 files changed

+319
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,39 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
784784
case X86::BI__builtin_ia32_insertf64x2_256:
785785
case X86::BI__builtin_ia32_inserti64x2_256:
786786
case X86::BI__builtin_ia32_insertf64x2_512:
787-
case X86::BI__builtin_ia32_inserti64x2_512:
788-
llvm_unreachable("insertf128 NYI");
787+
case X86::BI__builtin_ia32_inserti64x2_512: {
788+
unsigned dstNumElts = cast<cir::VectorType>(Ops[0].getType()).getSize();
789+
unsigned srcNumElts = cast<cir::VectorType>(Ops[1].getType()).getSize();
790+
unsigned subVectors = dstNumElts / srcNumElts;
791+
unsigned index =
792+
Ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue();
793+
assert(llvm::isPowerOf2_32(subVectors) && "Expected power of 2 subvectors");
794+
index &= subVectors - 1; // Remove any extra bits.
795+
index *= srcNumElts;
796+
797+
int64_t indices[16];
798+
for (unsigned i = 0; i != dstNumElts; ++i)
799+
indices[i] = (i >= srcNumElts) ? srcNumElts + (i % srcNumElts) : i;
800+
801+
cir::ConstantOp poisonVec =
802+
builder.getConstant(getLoc(E->getExprLoc()),
803+
builder.getAttr<cir::PoisonAttr>(Ops[1].getType()));
804+
805+
mlir::Value op1 =
806+
builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[1], poisonVec,
807+
ArrayRef(indices, dstNumElts));
808+
809+
for (unsigned i = 0; i != dstNumElts; ++i) {
810+
if (i >= index && i < (index + srcNumElts))
811+
indices[i] = (i - index) + dstNumElts;
812+
else
813+
indices[i] = i;
814+
}
815+
816+
return builder.createVecShuffle(getLoc(E->getExprLoc()), Ops[0], op1,
817+
ArrayRef(indices, dstNumElts));
818+
}
819+
789820
case X86::BI__builtin_ia32_pmovqd512_mask:
790821
case X86::BI__builtin_ia32_pmovwb512_mask:
791822
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
@@ -143,3 +143,36 @@ __m256i test_mm256_insert_epi64(__m256i x, long long b) {
143143
return _mm256_insert_epi64(x, b, 2);
144144
}
145145
#endif
146+
147+
__m256d test_mm256_insertf128_pd(__m256d A, __m128d B) {
148+
// CIR-LABEL: test_mm256_insertf128_pd
149+
// %{{.*}} = 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>
150+
// %{{.*}} = 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>
151+
152+
// LLVM-LABEL: test_mm256_insertf128_pd
153+
// LLVM: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
154+
// LLVM: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
155+
return _mm256_insertf128_pd(A, B, 0);
156+
}
157+
158+
__m256 test_mm256_insertf128_ps(__m256 A, __m128 B) {
159+
// CIR-LABEL: test_mm256_insertf128_ps
160+
// %{{.*}} = 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>
161+
// %{{.*}} = 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>
162+
163+
// LLVM-LABEL: test_mm256_insertf128_ps
164+
// 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>
165+
// 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>
166+
return _mm256_insertf128_ps(A, B, 1);
167+
}
168+
169+
__m256i test_mm256_insertf128_si256(__m256i A, __m128i B) {
170+
// CIR-LABEL: test_mm256_insertf128_si256
171+
// %{{.*}} = 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>
172+
// %{{.*}} = 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]
173+
174+
// LLVM-LABEL: test_mm256_insertf128_si256
175+
// 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>
176+
// 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>
177+
return _mm256_insertf128_si256(A, B, 0);
178+
}
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_pd_1(
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-NEXT: %{{.*}} = 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-NEXT: 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<!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>
61+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle([[TMP0]], %{{.*}} : !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>
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-NEXT: [[TMP0:%.*]] = bitcast <4 x i64> %{{.*}} to <8 x i32>
67+
// LLVM-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> %{{.*}} to <4 x i32>
68+
// LLVM-NEXT: [[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-NEXT: [[TMP2:%.*]] = bitcast <8 x i32> [[INSERT]] to <4 x i64>
71+
// LLVM-NEXT: 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<!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>
81+
// CIR-NEXT: %{{.*}} = cir.vec.shuffle([[TMP0]], %{{.*}} : !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>
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-NEXT: [[TMP0:%.*]] = bitcast <4 x i64> %{{.*}} to <8 x i32>
87+
// LLVM-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> %{{.*}} to <4 x i32>
88+
// LLVM-NEXT: [[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-NEXT: [[TMP2:%.*]] = bitcast <8 x i32> [[INSERT]] to <4 x i64>
91+
// LLVM-NEXT: 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+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
5+
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fclangir -emit-llvm -o %t.ll -Wall -Werror
7+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
8+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
9+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
10+
11+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fclangir -emit-cir -o %t.cir -Wall -Werror
12+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
13+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
14+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
15+
16+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fclangir -emit-llvm -o %t.ll -Wall -Werror
17+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
18+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx2 -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
19+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
20+
21+
#include <immintrin.h>
22+
23+
__m256i test0_mm256_inserti128_si256(__m256i a, __m128i b) {
24+
25+
// CIR-LABEL: test0_mm256_inserti128_si256
26+
// 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>
27+
// 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>
28+
29+
// LLVM-LABEL: test0_mm256_inserti128_si256
30+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
31+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
32+
return _mm256_inserti128_si256(a, b, 0);
33+
}
34+
35+
__m256i test1_mm256_inserti128_si256(__m256i a, __m128i b) {
36+
// CIR-LABEL: test1_mm256_inserti128_si256
37+
// 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>
38+
// 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>
39+
40+
// LLVM-LABEL: test1_mm256_inserti128_si256
41+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
42+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
43+
return _mm256_inserti128_si256(a, b, 1);
44+
}
45+
46+
// Immediate should be truncated to one bit.
47+
__m256i test2_mm256_inserti128_si256(__m256i a, __m128i b) {
48+
// CIR-LABEL: test2_mm256_inserti128_si256
49+
// 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>
50+
// 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>
51+
52+
// LLVM-LABEL: test2_mm256_inserti128_si256
53+
// LLVM: shufflevector <2 x i64> %{{.*}}, <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
54+
// LLVM: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
55+
return _mm256_inserti128_si256(a, b, 0);
56+
}
57+
58+
59+

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)