Skip to content

Commit 10536f5

Browse files
RiverDavelanza
authored andcommitted
[CIR][CIRGen][Builtin][X86] Lower AVX mask-to-vector conversion intrinsics (llvm#1738)
1 parent 4586707 commit 10536f5

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ static mlir::Value emitX86MaskedStore(CIRGenFunction &cgf,
108108
maskVec);
109109
}
110110

111+
static mlir::Value emitX86SExtMask(CIRGenFunction &cgf, mlir::Value op,
112+
mlir::Type dstTy, mlir::Location loc) {
113+
unsigned numberOfElements = cast<cir::VectorType>(dstTy).getSize();
114+
mlir::Value mask = getMaskVecValue(cgf, op, numberOfElements, loc);
115+
116+
return cgf.getBuilder().createCast(loc, cir::CastKind::integral, mask, dstTy);
117+
}
118+
111119
mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
112120
const CallExpr *E) {
113121
if (BuiltinID == Builtin::BI__builtin_cpu_is)
@@ -428,5 +436,19 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
428436
case X86::BI__builtin_ia32_storesd128_mask:
429437
return emitX86MaskedStore(*this, Ops, llvm::Align(1),
430438
getLoc(E->getExprLoc()));
439+
case X86::BI__builtin_ia32_cvtmask2b128:
440+
case X86::BI__builtin_ia32_cvtmask2b256:
441+
case X86::BI__builtin_ia32_cvtmask2b512:
442+
case X86::BI__builtin_ia32_cvtmask2w128:
443+
case X86::BI__builtin_ia32_cvtmask2w256:
444+
case X86::BI__builtin_ia32_cvtmask2w512:
445+
case X86::BI__builtin_ia32_cvtmask2d128:
446+
case X86::BI__builtin_ia32_cvtmask2d256:
447+
case X86::BI__builtin_ia32_cvtmask2d512:
448+
case X86::BI__builtin_ia32_cvtmask2q128:
449+
case X86::BI__builtin_ia32_cvtmask2q256:
450+
case X86::BI__builtin_ia32_cvtmask2q512:
451+
return emitX86SExtMask(*this, Ops[0], convertType(E->getType()),
452+
getLoc(E->getExprLoc()));
431453
}
432454
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ void test_mm512_mask_storeu_epi8(void *__P, __mmask64 __U, __m512i __A) {
2727
// LLVM: @llvm.masked.store.v64i8.p0(<64 x i8> %{{.*}}, ptr %{{.*}}, i32 1, <64 x i1> %{{.*}})
2828
return _mm512_mask_storeu_epi8(__P, __U, __A);
2929
}
30+
31+
__m512i test_mm512_movm_epi16(__mmask32 __A) {
32+
// CIR-LABEL: _mm512_movm_epi16
33+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u32i), !cir.vector<!cir.int<s, 1> x 32>
34+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 32>), !cir.vector<!s16i x 32>
35+
// LLVM-LABEL: @test_mm512_movm_epi16
36+
// LLVM: %{{.*}} = bitcast i32 %{{.*}} to <32 x i1>
37+
// LLVM: %{{.*}} = sext <32 x i1> %{{.*}} to <32 x i16>
38+
return _mm512_movm_epi16(__A);
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512dq -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512dq -fclangir -emit-llvm -o %t.ll -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
6+
#include <immintrin.h>
7+
8+
__m512i test_mm512_movm_epi64(__mmask8 __A) {
9+
// CIR-LABEL: _mm512_movm_epi64
10+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
11+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>), !cir.vector<!s64i x 8>
12+
// LLVM-LABEL: @test_mm512_movm_epi64
13+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
14+
// LLVM: %{{.*}} = sext <8 x i1> %{{.*}} to <8 x i64>
15+
return _mm512_movm_epi64(__A);
16+
}

clang/test/CIR/CodeGen/X86/avx512vlbw-buiiltins.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,58 @@ void test_mm256_mask_storeu_pd(void *__P, __mmask8 __U, __m256d __A) {
5151
// LLVM: @llvm.masked.store.v4f64.p0(<4 x double> %{{.*}}, ptr %{{.*}}, i32 1, <4 x i1> %{{.*}})
5252
return _mm256_mask_storeu_pd(__P, __U, __A);
5353
}
54+
55+
__m128i test_mm_movm_epi8(__mmask16 __A) {
56+
// CIR-LABEL: _mm_movm_epi8
57+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u16i), !cir.vector<!cir.int<s, 1> x 16>
58+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 16>), !cir.vector<{{!s8i|!u8i}} x 16>
59+
60+
// LLVM-LABEL: @test_mm_movm_epi8
61+
// LLVM: %{{.*}} = bitcast i16 %{{.*}} to <16 x i1>
62+
// LLVM: %{{.*}} = sext <16 x i1> %{{.*}} to <16 x i8>
63+
return _mm_movm_epi8(__A);
64+
}
65+
66+
__m256i test_mm256_movm_epi8(__mmask32 __A) {
67+
// CIR-LABEL: _mm256_movm_epi8
68+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u32i), !cir.vector<!cir.int<s, 1> x 32>
69+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 32>), !cir.vector<{{!s8i|!u8i}} x 32>
70+
71+
// LLVM-LABEL: @test_mm256_movm_epi8
72+
// LLVM: %{{.*}} = bitcast i32 %{{.*}} to <32 x i1>
73+
// LLVM: %{{.*}} = sext <32 x i1> %{{.*}} to <32 x i8>
74+
return _mm256_movm_epi8(__A);
75+
}
76+
77+
__m512i test_mm512_movm_epi8(__mmask64 __A) {
78+
// CIR-LABEL: _mm512_movm_epi8
79+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u64i), !cir.vector<!cir.int<s, 1> x 64>
80+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 64>), !cir.vector<{{!s8i|!u8i}} x 64>
81+
82+
// LLVM-LABEL: @test_mm512_movm_epi8
83+
// LLVM: %{{.*}} = bitcast i64 %{{.*}} to <64 x i1>
84+
// LLVM: %{{.*}} = sext <64 x i1> %{{.*}} to <64 x i8>
85+
return _mm512_movm_epi8(__A);
86+
}
87+
88+
__m128i test_mm_movm_epi16(__mmask8 __A) {
89+
// CIR-LABEL: _mm_movm_epi16
90+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
91+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>), !cir.vector<!s16i x 8>
92+
93+
// LLVM-LABEL: @test_mm_movm_epi16
94+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
95+
// LLVM: %{{.*}} = sext <8 x i1> %{{.*}} to <8 x i16>
96+
return _mm_movm_epi16(__A);
97+
}
98+
99+
__m256i test_mm256_movm_epi16(__mmask16 __A) {
100+
// CIR-LABEL: _mm256_movm_epi16
101+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u16i), !cir.vector<!cir.int<s, 1> x 16>
102+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 16>), !cir.vector<!s16i x 16>
103+
104+
// LLVM-LABEL: @test_mm256_movm_epi16
105+
// LLVM: %{{.*}} = bitcast i16 %{{.*}} to <16 x i1>
106+
// LLVM: %{{.*}} = sext <16 x i1> %{{.*}} to <16 x i16>
107+
return _mm256_movm_epi16(__A);
108+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512dq -target-feature +avx512vl -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512dq -target-feature +avx512vl -fclangir -emit-llvm -o %t.ll -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
6+
#include <immintrin.h>
7+
8+
__m128i test_mm_movm_epi32(__mmask8 __A) {
9+
// CIR-LABEL: _mm_movm_epi32
10+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
11+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.int<s, 1> x 4>
12+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 4>), !cir.vector<!s32i x 4>
13+
14+
// LLVM-LABEL: @test_mm_movm_epi32
15+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
16+
// LLVM: %{{.*}} = shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
17+
// LLVM: %{{.*}} = sext <4 x i1> %{{.*}} to <4 x i32>
18+
return _mm_movm_epi32(__A);
19+
}
20+
21+
__m256i test_mm256_movm_epi32(__mmask8 __A) {
22+
// CIR-LABEL: _mm256_movm_epi32
23+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
24+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>), !cir.vector<!s32i x 8>
25+
26+
// LLVM-LABEL: @test_mm256_movm_epi32
27+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
28+
// LLVM: %{{.*}} = sext <8 x i1> %{{.*}} to <8 x i32>
29+
return _mm256_movm_epi32(__A);
30+
}
31+
32+
__m512i test_mm512_movm_epi32(__mmask16 __A) {
33+
// CIR-LABEL: _mm512_movm_epi32
34+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u16i), !cir.vector<!cir.int<s, 1> x 16>
35+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 16>), !cir.vector<!s32i x 16>
36+
37+
// LLVM-LABEL: @test_mm512_movm_epi32
38+
// LLVM: %{{.*}} = bitcast i16 %{{.*}} to <16 x i1>
39+
// LLVM: %{{.*}} = sext <16 x i1> %{{.*}} to <16 x i32>
40+
return _mm512_movm_epi32(__A);
41+
}
42+
43+
__m128i test_mm_movm_epi64(__mmask8 __A) {
44+
// CIR-LABEL: _mm_movm_epi64
45+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
46+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i] : !cir.vector<!cir.int<s, 1> x 2>
47+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 2>), !cir.vector<!s64i x 2>
48+
49+
// LLVM-LABEL: @test_mm_movm_epi64
50+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
51+
// LLVM: %{{.*}} = shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <2 x i32> <i32 0, i32 1>
52+
// LLVM: %{{.*}} = sext <2 x i1> %{{.*}} to <2 x i64>
53+
return _mm_movm_epi64(__A);
54+
}
55+
56+
__m256i test_mm256_movm_epi64(__mmask8 __A) {
57+
// CIR-LABEL: _mm256_movm_epi64
58+
// CIR: %{{.*}} = cir.cast(bitcast, %{{.*}} : !u8i), !cir.vector<!cir.int<s, 1> x 8>
59+
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<!cir.int<s, 1> x 8>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<!cir.int<s, 1> x 4>
60+
// CIR: %{{.*}} = cir.cast(integral, %{{.*}} : !cir.vector<!cir.int<s, 1> x 4>), !cir.vector<!s64i x 4>
61+
62+
// LLVM-LABEL: @test_mm256_movm_epi64
63+
// LLVM: %{{.*}} = bitcast i8 %{{.*}} to <8 x i1>
64+
// LLVM: %{{.*}} = shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
65+
// LLVM: %{{.*}} = sext <4 x i1> %{{.*}} to <4 x i64>
66+
return _mm256_movm_epi64(__A);
67+
}

0 commit comments

Comments
 (0)