[clang] [clang] VectorExprEvaluator::VisitCallExpr - add constant folding for X86 pslldqi/psrldqi infrinsics (PR #157403)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 10 11:11:28 PDT 2025
================
@@ -12001,6 +12001,70 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
}
+ case X86::BI__builtin_ia32_pslldqi128_byteshift:
+ case X86::BI__builtin_ia32_psrldqi128_byteshift: {
+ unsigned BuiltinID = E->getBuiltinCallee();
+
+ APSInt Amt;
+ if (!EvaluateInteger(E->getArg(1), Amt, Info))
+ break;
+ unsigned Shift = (unsigned)Amt.getZExtValue();
+
+ APValue Vec;
+ if (!Evaluate(Vec, Info, E->getArg(0)) || !Vec.isVector())
+ break;
+
+ SmallVector<APValue, 16> ResultElements;
+ ResultElements.reserve(16);
+
+ bool isLeft = (BuiltinID == X86::BI__builtin_ia32_pslldqi128_byteshift);
+
+ for (unsigned i = 0; i < 16; i++) {
+ int SrcIdx = -1;
+ if (isLeft)
+ SrcIdx = i + Shift;
+ else if (i >= Shift)
+ SrcIdx = i - Shift;
+
+ if (SrcIdx >= 0 && (unsigned)SrcIdx < 16)
+ ResultElements.push_back(Vec.getVectorElt(SrcIdx));
----------------
RKSimon wrote:
This isn't going to work as currently the intrinsics take `<X x long long int>` types - we're going to have to change these to `<8X x char>` types to make this a lot easier to deal with - see the palignr builtins for an example
https://github.com/llvm/llvm-project/pull/157403
More information about the cfe-commits
mailing list