Skip to content

Commit 5e77e09

Browse files
committed
[CIR][CIRGen][Builtin][X86] Masked compress Intrinsics
This pr is related to the issue #167765 Added the support Masked compress builtin in CIR codeGen
1 parent 6bc66e5 commit 5e77e09

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
2525
mlir::Location loc, const StringRef str,
2626
const mlir::Type &resTy,
2727
Operands &&...op) {
28+
<<<<<<< HEAD
2829
return cir::LLVMIntrinsicCallOp::create(builder, loc,
30+
=======
31+
CIRGenBuilderTy &builder = cgf.getBuilder();
32+
mlir::Location location = cgf.getLoc(e->getExprLoc());
33+
llvm::SmallVector<mlir::Value> operands{std::forward<Operands>(op)...};
34+
return cir::LLVMIntrinsicCallOp::create(builder, location,
35+
>>>>>>> 320f8069e917 ([CIR][CIRGen][Builtin][X86] Masked compress Intrinsics)
2936
builder.getStringAttr(str), resTy,
30-
std::forward<Operands>(op)...)
37+
operands)
3138
.getResult();
3239
}
3340

@@ -84,13 +91,10 @@ static mlir::Value getMaskVecValue(CIRGenBuilderTy &builder, mlir::Location loc,
8491
}
8592
return maskVec;
8693
}
87-
static mlir::Value emitX86CompressExpand(CIRGenFunction &cgf, const CallExpr *expr,ArrayRef<mlir::Value> ops, bool IsCompress, const std::string &ID){
88-
auto ResultTy = cast<cir::VectorType>(ops[1].getType());
89-
mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2], cast<cir::VectorType>(ResultTy).getSize());
90-
llvm::SmallVector<mlir::Value, 4> op{ops[0], ops[1], MaskValue};
91-
92-
return emitIntrinsicCallOp(cgf,expr, ID, ResultTy, op);
93-
94+
static mlir::Value emitX86CompressExpand(CIRGenFunction &cgf, const CallExpr *expr, mlir::Value source, mlir::Value mask, mlir::Value inputVector, const std::string &id){
95+
auto ResultTy = cast<cir::VectorType>(mask.getType());
96+
mlir::Value MaskValue = getMaskVecValue(cgf, expr, inputVector, cast<cir::VectorType>(ResultTy).getSize());
97+
return emitIntrinsicCallOp(cgf,expr, id, ResultTy, source, mask, MaskValue);
9498
}
9599

96100
mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
@@ -447,6 +451,10 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
447451
case X86::BI__builtin_ia32_expandqi128_mask:
448452
case X86::BI__builtin_ia32_expandqi256_mask:
449453
case X86::BI__builtin_ia32_expandqi512_mask:
454+
cgm.errorNYI(expr->getSourceRange(),
455+
std::string("unimplemented X86 builtin call: ") +
456+
getContext().BuiltinInfo.getName(builtinID));
457+
return {};
450458
case X86::BI__builtin_ia32_compressdf128_mask:
451459
case X86::BI__builtin_ia32_compressdf256_mask:
452460
case X86::BI__builtin_ia32_compressdf512_mask:
@@ -465,7 +473,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
465473
case X86::BI__builtin_ia32_compressqi128_mask:
466474
case X86::BI__builtin_ia32_compressqi256_mask:
467475
case X86::BI__builtin_ia32_compressqi512_mask:{
468-
return emitX86CompressExpand(*this, expr, ops, true, "x86_avx512_mask_compress");
476+
return emitX86CompressExpand(*this, expr, ops[0], ops[1], ops[2], "x86_avx512_mask_compress");
469477
}
470478
case X86::BI__builtin_ia32_gather3div2df:
471479
case X86::BI__builtin_ia32_gather3div2di:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512vlvbmi2 -fclangir -emit-cir -o %t.cir -Wall -Werror -Wsign-conversion
3+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
4+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512vlvbmi2 -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion
5+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
6+
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512vlvbmi2 -fclangir -emit-cir -o %t.cir -Wall -Werror -Wsign-conversion
8+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
9+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512vlvbmi2 -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion
10+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
11+
12+
#include <immintrin.h>
13+
14+
__m128i test_mm_mask_compress_epi16(__m128i __S, __mmask8 __U, __m128i __D){
15+
// CIR-LABEL: cir.func {{.*}}@test_mm_mask_compress_epi16
16+
// CIR: call @_mm_mask_compress_epi16
17+
// CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.i16>
18+
19+
// LLVM-LABEL: @test_mm_mask_compress_epi16
20+
// LLVM: store <8 x i16> zeroinitializer, ptr %[[A:.*]], align 16
21+
// LLVM: %{{.*}} = load <8 x i16>, ptr %[[A]], align 16
22+
// LLVM: ret <8 x i16> %{{.*}}
23+
24+
// OGCG-LABEL: test_mm_mask_compress_epi16
25+
// OGCG: ret <8 x i16> zeroinitializer
26+
return (__m128i)_mm_mask_compress_epi16(__S, __U, __D);
27+
}

0 commit comments

Comments
 (0)