Skip to content

Conversation

@cs25mtech12008
Copy link

@cs25mtech12008 cs25mtech12008 commented Nov 26, 2025

Added builtin support for the multishift operation with test file.

changes has been done in CIRGenBuiltinX86 file
please review the changes and suggest if anything is missing

@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

@llvm/pr-subscribers-clang

Author: Omkar Rasal (cs25mtech12008)

Changes

Added builtin support for the multishift operation with test file.

changes has been done in CIRGenBuiltinX86 file


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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp (+7)
  • (added) clang/test/CIR/CodeGen/X86/builtin_multishift.c (+11)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index e7aa8a234efd9..4cbeecf0d8ea3 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -877,9 +877,16 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
   case X86::BI__builtin_ia32_vp2intersect_d_512:
   case X86::BI__builtin_ia32_vp2intersect_d_256:
   case X86::BI__builtin_ia32_vp2intersect_d_128:
+    cgm.errorNYI(expr->getSourceRange(),
+                 std::string("unimplemented X86 builtin call: ") +
+                     getContext().BuiltinInfo.getName(builtinID));
+    return {};
   case X86::BI__builtin_ia32_vpmultishiftqb128:
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128", ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpmultishiftqb256:
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_256", ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpmultishiftqb512:
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_512", ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
   case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
   case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
diff --git a/clang/test/CIR/CodeGen/X86/builtin_multishift.c b/clang/test/CIR/CodeGen/X86/builtin_multishift.c
new file mode 100644
index 0000000000000..7c57ef3191d1d
--- /dev/null
+++ b/clang/test/CIR/CodeGen/X86/builtin_multishift.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi \
+// RUN:   -fclangir -emit-cir %s -o - | FileCheck %s
+
+#include <immintrin.h>
+__m512i test_multishift(__m512i x, __m512i y) {
+  return _mm512_multishift_epi64_epi8(x, y);
+}
+
+// // CHECK: cir.func @test_multishift
+// // CHECK: cir.call @__builtin_ia32_vpmultishiftqb512
+

@cs25mtech12008 cs25mtech12008 marked this pull request as ready for review November 28, 2025 12:40
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 just a couple of requests for changes.

getContext().BuiltinInfo.getName(builtinID));
return {};
case X86::BI__builtin_ia32_vpmultishiftqb128:
return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128", ops[0].getType(), 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 emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128", ops[0].getType(), ops);
return emitIntrinsicCallOp(builder, getLoc(expr->getExprLoc()), "x86_avx512_pmultishift_qb_128", ops[0].getType(), ops);

You'll need to rebase your PR to get this new signature. It's been updated recently.

Comment on lines +1 to +2
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi \
// RUN: -fclangir -emit-cir %s -o - | FileCheck %s
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
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi \
// RUN: -fclangir -emit-cir %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir --check-prefix=CIR %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi -fclangir -emit-llvm %s -o %t-cir.ll
// RUN: FileCheck --input-file=%t-cir.ll --check-prefix=LLVM %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512vbmi -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll --check-prefix=OGCG %s

These lines perform the three variations of checks we expect.

However, this test should be moved to clang/test/CIR/CodeGenBuiltins/X86/avx512vbmi-builtins.c which is also being added in #169582

@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 c,cpp -- clang/test/CIR/CodeGen/X86/avx512vbmi-builtins.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 3ad653237..d3979d4ac 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -1453,11 +1453,14 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
                      getContext().BuiltinInfo.getName(builtinID));
     return {};
   case X86::BI__builtin_ia32_vpmultishiftqb128:
-    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128", ops[0].getType(), ops);
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128",
+                               ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpmultishiftqb256:
-    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_256", ops[0].getType(), ops);
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_256",
+                               ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpmultishiftqb512:
-    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_512", ops[0].getType(), ops);
+    return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_512",
+                               ops[0].getType(), ops);
   case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
   case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
   case X86::BI__builtin_ia32_vpshufbitqmb512_mask:

@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/CIRGenBuiltinX86.cpp.o
FAILED: tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenBuiltinX86.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/CIRGenBuiltinX86.cpp.o -MF tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenBuiltinX86.cpp.o.d -o tools/clang/lib/CIR/CodeGen/CMakeFiles/obj.clangCIR.dir/CIRGenBuiltinX86.cpp.o -c /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:1456:12: error: no matching function for call to 'emitIntrinsicCallOp'
1456 |     return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_128", ops[0].getType(), ops);
|            ^~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:28:20: note: candidate function template not viable: no known conversion from 'clang::CIRGen::CIRGenFunction' to 'CIRGenBuilderTy &' for 1st argument
28 | static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
|                    ^                   ~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:1458:12: error: no matching function for call to 'emitIntrinsicCallOp'
1458 |     return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_256", ops[0].getType(), ops);
|            ^~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:28:20: note: candidate function template not viable: no known conversion from 'clang::CIRGen::CIRGenFunction' to 'CIRGenBuilderTy &' for 1st argument
28 | static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
|                    ^                   ~~~~~~~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:1460:12: error: no matching function for call to 'emitIntrinsicCallOp'
1460 |     return emitIntrinsicCallOp(*this, expr, "x86_avx512_pmultishift_qb_512", ops[0].getType(), ops);
|            ^~~~~~~~~~~~~~~~~~~
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp:28:20: note: candidate function template not viable: no known conversion from 'clang::CIRGen::CIRGenFunction' to 'CIRGenBuilderTy &' for 1st argument
28 | static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
|                    ^                   ~~~~~~~~~~~~~~~~~~~~~~~~
3 errors 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.

Added builtin support for the multishift operation with test file.

changes has been done in CIRGenBuiltinX86 file
Copy link
Member

@bcardosolopes bcardosolopes 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 contribution, @cs25mtech12008 anything you need to get unblocked here?

return _mm512_multishift_epi64_epi8(x, y);
}

// // CHECK: cir.func @test_multishift
Copy link
Member

Choose a reason for hiding this comment

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

Double // here is not necessary

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.

4 participants