[llvm] [ConstantFolding] Add folding for [de]interleave2, insert and extract (PR #141301)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 13:01:10 PDT 2025
================
@@ -3911,6 +3993,26 @@ ConstantFoldStructCall(StringRef Name, Intrinsic::ID IntrinsicID,
return nullptr;
return ConstantStruct::get(StTy, SinResult, CosResult);
}
+ case Intrinsic::vector_deinterleave2: {
+ auto *Vec = dyn_cast<Constant>(Operands[0]);
+ if (!Vec)
+ return nullptr;
+
+ unsigned NumElements =
+ cast<VectorType>(Vec->getType())->getElementCount().getKnownMinValue() /
+ 2;
+ SmallVector<Constant *, 4> Res0(NumElements), Res1(NumElements);
+ for (unsigned I = 0; I < NumElements; ++I) {
+ Constant *Elt0 = Vec->getAggregateElement(2 * I);
+ Constant *Elt1 = Vec->getAggregateElement(2 * I + 1);
+ if (!Elt0 || !Elt1)
+ return nullptr;
+ Res0[I] = Elt0;
+ Res1[I] = Elt1;
+ }
+ return ConstantStruct::get(StTy, ConstantVector::get(Res0),
----------------
topperc wrote:
I guess we just get lucky because `ConstantStruct::get` checks that the input constants are all zero without ever verifying the types. If someone adds an assert to ConstantStruct::get this breaks.
https://github.com/llvm/llvm-project/pull/141301
More information about the llvm-commits
mailing list