[llvm] sketch idea of getConstantBuildVector (PR #180074)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 02:29:26 PST 2026
================
@@ -2194,6 +2194,46 @@ SDValue SelectionDAG::getMaskFromElementCount(const SDLoc &DL, EVT DataVT,
getConstant(0, DL, IdxVT), getElementCount(DL, IdxVT, EC));
}
+SDValue SelectionDAG::getConstantBuildVector(EVT VT, const SDLoc &DL,
+ ArrayRef<APInt> Ops,
+ const APInt &UndefElts) {
+ assert(VT.isFixedLengthVector() && "Expected fixed-length vector type");
+ assert(VT.getVectorNumElements() == Ops.size() &&
+ "Mismatch between VT element count and Ops size");
+ assert(UndefElts.getBitWidth() == Ops.size() &&
+ "Mismatch between UndefElts width and Ops size");
+ unsigned NumElts = VT.getVectorNumElements();
+ EVT EltVT = VT.getVectorElementType();
+ assert(EltVT.isInteger() && "Expected integer element type");
+ // Determine the type to use for the constant elements. After type
+ // legalization, the original scalar element type may be illegal (e.g., i32
+ // on LoongArch64 where only i64 is legal). In that case, we promote to a
+ // legal type and rely on BUILD_VECTOR's implicit truncation.
+ EVT ConstantVT = EltVT;
+ if (NewNodesMustHaveLegalTypes) {
+ auto Action = TLI->getTypeAction(*getContext(), EltVT);
+ if (Action == TargetLowering::TypePromoteInteger)
+ ConstantVT = TLI->getTypeToTransformTo(*getContext(), EltVT);
+ }
+ SmallVector<SDValue, 16> BVOps(NumElts);
+ for (unsigned i = 0; i < NumElts; ++i) {
+ if (UndefElts[i]) {
+ BVOps[i] = getUNDEF(ConstantVT);
+ } else {
+
+ APInt Val = Ops[i];
+ if (ConstantVT.getSizeInBits() > EltVT.getSizeInBits()) {
+ if (TLI->isSExtCheaperThanZExt(EltVT, ConstantVT))
----------------
natanelh-mobileye wrote:
why are we SExting or ZExting a constant? the result is a constant node anyway, is there a reason to prefer one or the other?
https://github.com/llvm/llvm-project/pull/180074
More information about the llvm-commits
mailing list