[llvm] [AMDGPU] Legalize 64bit elements for BUILD_VECTOR (PR #145052)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 06:47:07 PDT 2026
================
@@ -19121,6 +19163,92 @@ SDValue SITargetLowering::performSelectCombine(SDNode *N,
SelectLHS, SelectRHS);
}
+SDValue
+SITargetLowering::performBuildVectorCombine(SDNode *N,
+ DAGCombinerInfo &DCI) const {
+ // TODO: Perform for all targets instead of just v_mov_b64 enabled ones,
+ // lower could still enable s_mov_b64 which is supported on all targets.
+ const GCNSubtarget *ST = getSubtarget();
+ if (DCI.Level < AfterLegalizeDAG || !ST->hasVMovB64Inst())
+ return SDValue();
+
+ SelectionDAG &DAG = DCI.DAG;
+ SDLoc SL(N);
+
+ EVT VT = N->getValueType(0);
+ EVT EltVT = VT.getVectorElementType();
+ unsigned SizeBits = VT.getSizeInBits();
+ unsigned EltSize = EltVT.getSizeInBits();
+
+ // Skip if:
+ // - Value type isn't multiple of 64 bit (e.g., v3i32), or
+ // - Element type has already been combined into 64b elements
+ if ((SizeBits % 64) != 0 || EltSize == 64)
+ return SDValue();
+
+ SmallVector<APInt, 8> SrcBits;
+ BitVector SrcUndef(N->getNumOperands(), false);
+ for (SDValue Operand : N->ops()) {
+ // Build_vector with constants only.
+ ConstantSDNode *C = dyn_cast<ConstantSDNode>(Operand);
+ ConstantFPSDNode *FPC = dyn_cast<ConstantFPSDNode>(Operand);
+ BuildVectorSDNode *BV =
+ dyn_cast<BuildVectorSDNode>(peekThroughBitcasts(Operand));
+
+ if (!C && !FPC && !BV)
+ return SDValue();
+
+ APInt Elt;
+ if (BV) {
+ BitVector Undef;
+ SmallVector<APInt> Elts;
+ if (!BV->getConstantRawBits(/*IsLittleEndian=*/true, EltSize, Elts,
+ Undef))
+ return SDValue();
+ assert(Elts.size() == 1 &&
+ "BuildVector constant value retrieval expected 1 element");
+ if (Undef.any())
+ return SDValue();
----------------
arsenm wrote:
Undef should not be a pessimization, you can just choose 0 for it
https://github.com/llvm/llvm-project/pull/145052
More information about the llvm-commits
mailing list