Skip to content

Conversation

@AnkitDubeycs25
Copy link

This is my first commit. Requesting reviews.

This is my first commit. Requesting reviews.
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Nov 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2025

@llvm/pr-subscribers-clangir

Author: AnkitDubeycs25 (AnkitDubeycs25)

Changes

This is my first commit. Requesting reviews.


Full diff: https://github.com/llvm/llvm-project/pull/169648.diff

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp (+15-1)
  • (added) clang/test/CIR/CodeGen/X86/compressStore_builtin.c (+5)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index e7aa8a234efd9..5c3e7f7512851 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -90,6 +90,14 @@ static mlir::Value getMaskVecValue(CIRGenFunction &cgf, const CallExpr *expr,
   return maskVec;
 }
 
+static mlir::Value emitX86CompressStore(CIRGenFunction &cgf, const CallExpr *expr, ArrayRef<mlir::Value> ops){
+  auto ResultTy = cast<cir::VectorType>(ops[1].getType());
+  mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2],  cast<cir::VectorType>(ResultTy).getSize());
+  mlir::Value ptr = ops[0];
+
+  return emitIntrinsicCallOp(cgf, expr, "masked_compressstore", ResultTy, llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
+
+}
 mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
                                                const CallExpr *expr) {
   if (builtinID == Builtin::BI__builtin_cpu_is) {
@@ -400,7 +408,12 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_expandloadhi512_mask:
   case X86::BI__builtin_ia32_expandloadqi128_mask:
   case X86::BI__builtin_ia32_expandloadqi256_mask:
-  case X86::BI__builtin_ia32_expandloadqi512_mask:
+  case X86::BI__builtin_ia32_expandloadqi512_mask:{
+    cgm.errorNYI(expr->getSourceRange(),
+                 std::string("unimplemented X86 builtin call: ") +
+                     getContext().BuiltinInfo.getName(builtinID));
+    return {};
+  }
   case X86::BI__builtin_ia32_compressstoredf128_mask:
   case X86::BI__builtin_ia32_compressstoredf256_mask:
   case X86::BI__builtin_ia32_compressstoredf512_mask:
@@ -419,6 +432,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_compressstoreqi128_mask:
   case X86::BI__builtin_ia32_compressstoreqi256_mask:
   case X86::BI__builtin_ia32_compressstoreqi512_mask:
+    return emitX86CompressStore(*this, expr, ops);
   case X86::BI__builtin_ia32_expanddf128_mask:
   case X86::BI__builtin_ia32_expanddf256_mask:
   case X86::BI__builtin_ia32_expanddf512_mask:
diff --git a/clang/test/CIR/CodeGen/X86/compressStore_builtin.c b/clang/test/CIR/CodeGen/X86/compressStore_builtin.c
new file mode 100644
index 0000000000000..1407e21428aee
--- /dev/null
+++ b/clang/test/CIR/CodeGen/X86/compressStore_builtin.c
@@ -0,0 +1,5 @@
+#include <immintrin.h>
+
+void test_compress_store(void *__P, __mmask8 __U, __m128d __A){
+    return _mm_mask_compressstoreu_pd (__P, __U, __A);
+}
\ No newline at end of file

@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2025

@llvm/pr-subscribers-clang

Author: AnkitDubeycs25 (AnkitDubeycs25)

Changes

This is my first commit. Requesting reviews.


Full diff: https://github.com/llvm/llvm-project/pull/169648.diff

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp (+15-1)
  • (added) clang/test/CIR/CodeGen/X86/compressStore_builtin.c (+5)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index e7aa8a234efd9..5c3e7f7512851 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -90,6 +90,14 @@ static mlir::Value getMaskVecValue(CIRGenFunction &cgf, const CallExpr *expr,
   return maskVec;
 }
 
+static mlir::Value emitX86CompressStore(CIRGenFunction &cgf, const CallExpr *expr, ArrayRef<mlir::Value> ops){
+  auto ResultTy = cast<cir::VectorType>(ops[1].getType());
+  mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2],  cast<cir::VectorType>(ResultTy).getSize());
+  mlir::Value ptr = ops[0];
+
+  return emitIntrinsicCallOp(cgf, expr, "masked_compressstore", ResultTy, llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
+
+}
 mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
                                                const CallExpr *expr) {
   if (builtinID == Builtin::BI__builtin_cpu_is) {
@@ -400,7 +408,12 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_expandloadhi512_mask:
   case X86::BI__builtin_ia32_expandloadqi128_mask:
   case X86::BI__builtin_ia32_expandloadqi256_mask:
-  case X86::BI__builtin_ia32_expandloadqi512_mask:
+  case X86::BI__builtin_ia32_expandloadqi512_mask:{
+    cgm.errorNYI(expr->getSourceRange(),
+                 std::string("unimplemented X86 builtin call: ") +
+                     getContext().BuiltinInfo.getName(builtinID));
+    return {};
+  }
   case X86::BI__builtin_ia32_compressstoredf128_mask:
   case X86::BI__builtin_ia32_compressstoredf256_mask:
   case X86::BI__builtin_ia32_compressstoredf512_mask:
@@ -419,6 +432,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_compressstoreqi128_mask:
   case X86::BI__builtin_ia32_compressstoreqi256_mask:
   case X86::BI__builtin_ia32_compressstoreqi512_mask:
+    return emitX86CompressStore(*this, expr, ops);
   case X86::BI__builtin_ia32_expanddf128_mask:
   case X86::BI__builtin_ia32_expanddf256_mask:
   case X86::BI__builtin_ia32_expanddf512_mask:
diff --git a/clang/test/CIR/CodeGen/X86/compressStore_builtin.c b/clang/test/CIR/CodeGen/X86/compressStore_builtin.c
new file mode 100644
index 0000000000000..1407e21428aee
--- /dev/null
+++ b/clang/test/CIR/CodeGen/X86/compressStore_builtin.c
@@ -0,0 +1,5 @@
+#include <immintrin.h>
+
+void test_compress_store(void *__P, __mmask8 __U, __m128d __A){
+    return _mm_mask_compressstoreu_pd (__P, __U, __A);
+}
\ No newline at end of file

@AnkitDubeycs25 AnkitDubeycs25 marked this pull request as ready for review November 28, 2025 12:30
Copy link
Contributor

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! I have a few requests for changes.

@@ -0,0 +1,5 @@
#include <immintrin.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be moved to clang/test/CIR/CodeGenBuiltins/X86/avx512vl-builtins.c which is also being added in #169582. The test will need RUN lines and CIR, LLVM, and OGCG checks added.

mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2], cast<cir::VectorType>(ResultTy).getSize());
mlir::Value ptr = ops[0];

return emitIntrinsicCallOp(cgf, expr, "masked_compressstore", ResultTy, llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return emitIntrinsicCallOp(cgf, expr, "masked_compressstore", ResultTy, llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
return emitIntrinsicCallOp(builder, loc, "masked_compressstore", ResultTy, mlir::ValueRange{ops[1], ptr, MaskValue});

return maskVec;
}

static mlir::Value emitX86CompressStore(CIRGenFunction &cgf, const CallExpr *expr, ArrayRef<mlir::Value> ops){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static mlir::Value emitX86CompressStore(CIRGenFunction &cgf, const CallExpr *expr, ArrayRef<mlir::Value> ops){
static mlir::Value emitX86CompressStore(CIRGenBuilderTy &builder, mlir::Location loc, ArrayRef<mlir::Value> ops){

The signature of emitIntrinsicCallOp has recently been updated. This change makes the function you are adding consistent with it.

case X86::BI__builtin_ia32_compressstoreqi128_mask:
case X86::BI__builtin_ia32_compressstoreqi256_mask:
case X86::BI__builtin_ia32_compressstoreqi512_mask:
return emitX86CompressStore(*this, expr, ops);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return emitX86CompressStore(*this, expr, ops);
return emitX86CompressStore(builder, getLoc(expr->getExprLoc()), ops);

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp,c -- clang/test/CIR/CodeGen/X86/compressStore_builtin.c clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index 5c3e7f751..d45ee7e90 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -90,13 +90,17 @@ static mlir::Value getMaskVecValue(CIRGenFunction &cgf, const CallExpr *expr,
   return maskVec;
 }
 
-static mlir::Value emitX86CompressStore(CIRGenFunction &cgf, const CallExpr *expr, ArrayRef<mlir::Value> ops){
+static mlir::Value emitX86CompressStore(CIRGenFunction &cgf,
+                                        const CallExpr *expr,
+                                        ArrayRef<mlir::Value> ops) {
   auto ResultTy = cast<cir::VectorType>(ops[1].getType());
-  mlir::Value MaskValue = getMaskVecValue(cgf, expr, ops[2],  cast<cir::VectorType>(ResultTy).getSize());
+  mlir::Value MaskValue = getMaskVecValue(
+      cgf, expr, ops[2], cast<cir::VectorType>(ResultTy).getSize());
   mlir::Value ptr = ops[0];
 
-  return emitIntrinsicCallOp(cgf, expr, "masked_compressstore", ResultTy, llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
-
+  return emitIntrinsicCallOp(
+      cgf, expr, "masked_compressstore", ResultTy,
+      llvm::SmallVector<mlir::Value, 3>{ops[1], ptr, MaskValue});
 }
 mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
                                                const CallExpr *expr) {
@@ -408,7 +412,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_expandloadhi512_mask:
   case X86::BI__builtin_ia32_expandloadqi128_mask:
   case X86::BI__builtin_ia32_expandloadqi256_mask:
-  case X86::BI__builtin_ia32_expandloadqi512_mask:{
+  case X86::BI__builtin_ia32_expandloadqi512_mask: {
     cgm.errorNYI(expr->getSourceRange(),
                  std::string("unimplemented X86 builtin call: ") +
                      getContext().BuiltinInfo.getName(builtinID));

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

🐧 Linux x64 Test Results

  • 3053 tests passed
  • 7 tests skipped

All tests passed but another part of the build failed. Click on a failure below to see the details.

tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenAtomic.cpp.o
FAILED: tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenAtomic.cpp.o
sccache /opt/llvm/bin/clang++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/lib/CIR/CodeGen -I/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen -I/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/../mlir/include -I/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/mlir/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenAtomic.cpp.o -MF tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenAtomic.cpp.o.d -o tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenAtomic.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp:419:11: error: enumeration values 'AO__scoped_atomic_udec_wrap' and 'AO__scoped_atomic_uinc_wrap' not handled in switch [-Werror,-Wswitch]
419 |   switch (expr->getOp()) {
|           ^~~~~~~~~~~~~
1 error generated.

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants