https://github.com/cs25resch11005-bhuvan updated 
https://github.com/llvm/llvm-project/pull/169582

>From 6bc66e5d10106aa3d13d9dfcc9f85c3f2259889d Mon Sep 17 00:00:00 2001
From: bhuvan1527 <[email protected]>
Date: Wed, 26 Nov 2025 05:11:22 +0530
Subject: [PATCH 1/2] [CIR][CIRGen][Builtin][X86] Masked compress Intrinsics

Added masked compress builtin in CIR.
Note: This is my first PR to llvm.
---
 clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index a0ee57f82a04f..fe595890b60f7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -84,6 +84,14 @@ static mlir::Value getMaskVecValue(CIRGenBuilderTy &builder, 
mlir::Location loc,
   }
   return maskVec;
 }
+static mlir::Value emitX86CompressExpand(CIRGenFunction &cgf, const CallExpr 
*expr,ArrayRef<mlir::Value> ops, bool IsCompress, const std::string &ID){
+  auto ResultTy = cast<cir::VectorType>(ops[1].getType());
+  mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2],  
cast<cir::VectorType>(ResultTy).getSize());
+  llvm::SmallVector<mlir::Value, 4> op{ops[0], ops[1], MaskValue};
+  
+  return emitIntrinsicCallOp(cgf,expr, ID, ResultTy, op);
+
+}
 
 mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
                                                const CallExpr *expr) {
@@ -456,7 +464,9 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned 
builtinID,
   case X86::BI__builtin_ia32_compresshi512_mask:
   case X86::BI__builtin_ia32_compressqi128_mask:
   case X86::BI__builtin_ia32_compressqi256_mask:
-  case X86::BI__builtin_ia32_compressqi512_mask:
+  case X86::BI__builtin_ia32_compressqi512_mask:{
+    return emitX86CompressExpand(*this, expr, ops, true, 
"x86_avx512_mask_compress");
+  }
   case X86::BI__builtin_ia32_gather3div2df:
   case X86::BI__builtin_ia32_gather3div2di:
   case X86::BI__builtin_ia32_gather3div4df:

>From 5e77e0951fac6c8b8a79854a92d8b490396bd749 Mon Sep 17 00:00:00 2001
From: bhuvan1527 <[email protected]>
Date: Thu, 27 Nov 2025 19:59:41 +0530
Subject: [PATCH 2/2] [CIR][CIRGen][Builtin][X86] Masked compress Intrinsics

This pr is related to the issue #167765
Added the support Masked compress builtin in CIR codeGen
---
 clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp    | 26 +++++++++++-------
 .../X86/avx512vlvbmi2-builtins.c              | 27 +++++++++++++++++++
 2 files changed, 44 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/CIR/CodeGenBuiltins/X86/avx512vlvbmi2-builtins.c

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index fe595890b60f7..395ba23e47cbb 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -25,9 +25,16 @@ static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy 
&builder,
                                        mlir::Location loc, const StringRef str,
                                        const mlir::Type &resTy,
                                        Operands &&...op) {
+<<<<<<< HEAD
   return cir::LLVMIntrinsicCallOp::create(builder, loc,
+=======
+  CIRGenBuilderTy &builder = cgf.getBuilder();
+  mlir::Location location = cgf.getLoc(e->getExprLoc());
+  llvm::SmallVector<mlir::Value> operands{std::forward<Operands>(op)...};
+  return cir::LLVMIntrinsicCallOp::create(builder, location,
+>>>>>>> 320f8069e917 ([CIR][CIRGen][Builtin][X86] Masked compress Intrinsics)
                                           builder.getStringAttr(str), resTy,
-                                          std::forward<Operands>(op)...)
+                                          operands)
       .getResult();
 }
 
@@ -84,13 +91,10 @@ static mlir::Value getMaskVecValue(CIRGenBuilderTy 
&builder, mlir::Location loc,
   }
   return maskVec;
 }
-static mlir::Value emitX86CompressExpand(CIRGenFunction &cgf, const CallExpr 
*expr,ArrayRef<mlir::Value> ops, bool IsCompress, const std::string &ID){
-  auto ResultTy = cast<cir::VectorType>(ops[1].getType());
-  mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2],  
cast<cir::VectorType>(ResultTy).getSize());
-  llvm::SmallVector<mlir::Value, 4> op{ops[0], ops[1], MaskValue};
-  
-  return emitIntrinsicCallOp(cgf,expr, ID, ResultTy, op);
-
+static mlir::Value emitX86CompressExpand(CIRGenFunction &cgf, const CallExpr 
*expr, mlir::Value source, mlir::Value mask, mlir::Value inputVector, const 
std::string &id){
+  auto ResultTy = cast<cir::VectorType>(mask.getType());
+  mlir::Value MaskValue = getMaskVecValue(cgf, expr, inputVector,  
cast<cir::VectorType>(ResultTy).getSize());
+  return emitIntrinsicCallOp(cgf,expr, id, ResultTy, source, mask, MaskValue);
 }
 
 mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
@@ -447,6 +451,10 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned 
builtinID,
   case X86::BI__builtin_ia32_expandqi128_mask:
   case X86::BI__builtin_ia32_expandqi256_mask:
   case X86::BI__builtin_ia32_expandqi512_mask:
+    cgm.errorNYI(expr->getSourceRange(),
+                 std::string("unimplemented X86 builtin call: ") +
+                     getContext().BuiltinInfo.getName(builtinID));
+    return {};
   case X86::BI__builtin_ia32_compressdf128_mask:
   case X86::BI__builtin_ia32_compressdf256_mask:
   case X86::BI__builtin_ia32_compressdf512_mask:
@@ -465,7 +473,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned 
builtinID,
   case X86::BI__builtin_ia32_compressqi128_mask:
   case X86::BI__builtin_ia32_compressqi256_mask:
   case X86::BI__builtin_ia32_compressqi512_mask:{
-    return emitX86CompressExpand(*this, expr, ops, true, 
"x86_avx512_mask_compress");
+    return emitX86CompressExpand(*this, expr, ops[0], ops[1], ops[2], 
"x86_avx512_mask_compress");
   }
   case X86::BI__builtin_ia32_gather3div2df:
   case X86::BI__builtin_ia32_gather3div2di:
diff --git a/clang/test/CIR/CodeGenBuiltins/X86/avx512vlvbmi2-builtins.c 
b/clang/test/CIR/CodeGenBuiltins/X86/avx512vlvbmi2-builtins.c
new file mode 100644
index 0000000000000..7ffa66f9b9d88
--- /dev/null
+++ b/clang/test/CIR/CodeGenBuiltins/X86/avx512vlvbmi2-builtins.c
@@ -0,0 +1,27 @@
+
+// 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
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// 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
+// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
+
+// 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
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// 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
+// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
+
+#include <immintrin.h>
+
+__m128i test_mm_mask_compress_epi16(__m128i __S, __mmask8 __U, __m128i __D){
+    // CIR-LABEL: cir.func {{.*}}@test_mm_mask_compress_epi16
+    // CIR: call @_mm_mask_compress_epi16
+    // CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.i16>
+
+    // LLVM-LABEL: @test_mm_mask_compress_epi16
+    // LLVM: store <8 x i16> zeroinitializer, ptr %[[A:.*]], align 16
+    // LLVM: %{{.*}} = load <8 x i16>, ptr %[[A]], align 16
+    // LLVM: ret <8 x i16> %{{.*}}
+
+    // OGCG-LABEL: test_mm_mask_compress_epi16
+    // OGCG: ret <8 x i16> zeroinitializer
+    return (__m128i)_mm_mask_compress_epi16(__S, __U, __D);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to