[llvm] [ConstantFolding] Add folding for [de]interleave2, insert and extract (PR #141301)
Nikolay Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 09:22:05 PDT 2025
================
@@ -3750,6 +3754,84 @@ static Constant *ConstantFoldFixedVectorCall(
}
return nullptr;
}
+ case Intrinsic::vector_extract: {
+ auto *Idx = dyn_cast<ConstantInt>(Operands[1]);
+ Constant *Vec = Operands[0];
+ if (!Idx || !isa<FixedVectorType>(Vec->getType()))
+ return nullptr;
+
+ unsigned NumElements = FVTy->getNumElements();
+ unsigned VecNumElements =
+ cast<FixedVectorType>(Vec->getType())->getNumElements();
+ unsigned StartingIndex = Idx->getZExtValue();
+
+ // Extracting entire vector is nop
+ if (NumElements == VecNumElements && StartingIndex == 0)
+ return Vec;
+
+ const unsigned NonPoisonNumElements =
+ std::min(StartingIndex + NumElements, VecNumElements);
+ for (unsigned I = StartingIndex; I < NonPoisonNumElements; ++I) {
+ Constant *Elt = Vec->getAggregateElement(I);
+ if (!Elt)
+ return nullptr;
+ Result[I - StartingIndex] = Elt;
+ }
+
+ // Remaining elements are poison since they are out of bounds.
----------------
npanchen wrote:
That goes to that https://github.com/llvm/llvm-project/pull/141301#discussion_r2111053420 thread. Depending on a consensus, this code will either be removed or kept
https://github.com/llvm/llvm-project/pull/141301
More information about the llvm-commits
mailing list