[clang] [X86] Allow PSHUFD/PSHUFLW/PSHUFW intrinsics in constexpr. (PR #161210)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 30 11:14:31 PDT 2025


================
@@ -2862,6 +2862,68 @@ static bool interp__builtin_blend(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+enum class Half { None, Low, High };
+
+static bool interp__builtin_ia32_pshuf(InterpState &S, CodePtr OpPC, const CallExpr *Call,
+                                       Half whichHalf) {
+  assert(Call->getNumArgs() == 2 && "masked forms handled via select*");
+  APSInt controlImm = popToAPSInt(S, Call->getArg(1));
+  const Pointer &src = S.Stk.pop<Pointer>();
+  const Pointer &Dst = S.Stk.peek<Pointer>();
+
+  const unsigned numElts = Dst.getNumElems();
+  const PrimType elemTy  = Dst.getFieldDesc()->getPrimType();
+
+  // Only i16/i32 supported
+  const unsigned elemBits = static_cast<unsigned>(primSize(elemTy) * 8);
+  if (elemBits != 16 && elemBits != 32) return false;
+
+  // Lane: 64b for MMX, 128b otherwise
+  const unsigned totalBits = numElts * elemBits;
----------------
tbaederr wrote:

Capitalization of local variables is wrong.
We also don't make locals `const` unless it's a pointer or a reference.

https://github.com/llvm/llvm-project/pull/161210


More information about the cfe-commits mailing list