Skip to content

Conversation

@stomfaig
Copy link
Contributor

adding cases for vpermilpd and vpermilps in InterpBultin.

Resolves #166529

@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 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Nov 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2025

@llvm/pr-subscribers-clang

Author: None (stomfaig)

Changes

adding cases for vpermilpd and vpermilps in InterpBultin.

Resolves #166529


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

1 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+30)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index cee3c1b8cf8f3..9ea66c6de7553 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -4562,6 +4562,36 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
           unsigned Sel = (ShuffleMask >> (2 * LaneIdx)) & 0x3;
           return std::make_pair(0, static_cast<int>(LaneBase + Sel));
         });
+  
+  case X86::BI__builtin_ia32_vpermilpd:
+  case X86::BI__builtin_ia32_vpermilpd256:
+  case X86::BI__builtin_ia32_vpermilpd512:
+    return interp__builtin_ia32_shuffle_generic(S, OpPC, Call, [](unsigned DstIdx, unsigned Control) {
+      unsigned NumElemPerLane = 2;
+      unsigned BitsPerElem = 1;
+      unsigned MaskBits = 8;
+      unsigned IndexMask = 0x1;
+      unsigned Lane = DstIdx / NumElemPerLane;
+      unsigned LaneOffset = Lane * NumElemPerLane;
+      unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
+      unsigned Index = (Control >> BitIndex) & IndexMask;
+      return std::make_pair(0, static_cast<int>(LaneOffset + Index));
+    });
+  
+  case X86::BI__builtin_ia32_vpermilps:
+  case X86::BI__builtin_ia32_vpermilps256:
+  case X86::BI__builtin_ia32_vpermilps512:
+    return interp__builtin_ia32_shuffle_generic(S, OpPC, Call, [](unsigned DstIdx, unsigned Control) {
+      unsigned NumElemPerLane = 4;
+      unsigned BitsPerElem = 2;
+      unsigned MaskBits = 8;
+      unsigned IndexMask = 0x3;
+      unsigned Lane = DstIdx / NumElemPerLane;
+      unsigned LaneOffset = Lane * NumElemPerLane;
+      unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
+      unsigned Index = (Control >> BitIndex) & IndexMask;
+      return std::make_pair(0, static_cast<int>(LaneOffset + Index));
+    });
 
   case X86::BI__builtin_ia32_kandqi:
   case X86::BI__builtin_ia32_kandhi:

@tbaederr tbaederr requested a review from RKSimon November 14, 2025 12:03
@tbaederr
Copy link
Contributor

This is missing changes to ExprConstant.cpp and tests.

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

Still missing ExprConstant handling and test coverage

return std::make_pair(0, static_cast<int>(LaneOffset + Index));
});

case X86::BI__builtin_ia32_vpermilps:
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should match the PSHUFD handling - we can just add permilps as additional cases to that

@RKSimon RKSimon changed the title adding cases for vpermilpd and vpermilps [Clang][X86] allow VPERMILPD/S imm intrinsics to be used in constexpr Nov 14, 2025
@github-actions
Copy link

github-actions bot commented Nov 14, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@stomfaig
Copy link
Contributor Author

stomfaig commented Nov 14, 2025

Sorry for the oversight, I moved vpermilps under pshufd handling and added ExprConstant impl.

@RKSimon RKSimon self-requested a review November 18, 2025 11:12
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

test cases - again, _mm_permute_ps etc. can be adapted from existing _mm_shuffle_epi32 sse2/avx2/mask/maskz TEST_CONSTEXPR tests, but _mm_permute_pd etc will need fresh tests

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

LGTM - cheers

@RKSimon RKSimon enabled auto-merge (squash) November 19, 2025 11:24
@RKSimon RKSimon merged commit 50791c3 into llvm:main Nov 19, 2025
9 of 10 checks passed
@github-actions
Copy link

@stomfaig Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

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

Labels

backend:X86 clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow VPERMILPD/S imm intrinsics to be used in constexpr

4 participants