[llvm] [AMDGPU][SDAG] Legalise v2i32 or/xor/and instructions to make use of 64-bit wide instructions (PR #140694)
Janek van Oirschot via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 14 06:36:39 PDT 2025
================
@@ -3225,29 +3225,51 @@ bool AMDGPUDAGToDAGISel::SelectVOP3ModsImpl(SDValue In, SDValue &Src,
if (IsCanonicalizing)
return true;
- unsigned Opc = Src->getOpcode();
+ // v2i32 xor/or/and are legal. A vselect using these instructions as operands
+ // is scalarised into two selects with EXTRACT_VECTOR_ELT operands. Peek
+ // through the extract to the bitwise op.
+ SDValue PeekSrc =
+ Src->getOpcode() == ISD::EXTRACT_VECTOR_ELT ? Src->getOperand(0) : Src;
+ // Convert various sign-bit masks to src mods. Currently disabled for 16-bit
+ // types as the codegen replaces the operand without adding a srcmod.
+ // This is intentionally finding the cases where we are performing float neg
+ // and abs on int types, the goal is not to obtain two's complement neg or
+ // abs.
+ // TODO: Add 16-bit support.
+ unsigned Opc = PeekSrc.getOpcode();
EVT VT = Src.getValueType();
if ((Opc != ISD::AND && Opc != ISD::OR && Opc != ISD::XOR) ||
- (VT != MVT::i32 && VT != MVT::i64))
+ (VT != MVT::i32 && VT != MVT::v2i32 && VT != MVT::i64))
return true;
- ConstantSDNode *CRHS = dyn_cast<ConstantSDNode>(Src->getOperand(1));
+ ConstantSDNode *CRHS = isConstOrConstSplat(PeekSrc ? PeekSrc->getOperand(1)
+ : Src->getOperand(1));
if (!CRHS)
return true;
+ auto ReplaceSrc = [&]() -> SDValue {
+ if (Src->getOpcode() != ISD::EXTRACT_VECTOR_ELT)
+ return PeekSrc.getOperand(0);
+
+ SDValue LHS = PeekSrc->getOperand(0);
+ SDValue Index = Src->getOperand(1);
+ return CurDAG->getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Src),
+ Src.getValueType(), LHS, Index);
+ };
+
// Recognise (xor a, 0x80000000) as NEG SrcMod.
// Recognise (and a, 0x7fffffff) as ABS SrcMod.
// Recognise (or a, 0x80000000) as NEG+ABS SrcModifiers.
----------------
JanekvO wrote:
Update the recognise list for v2i32 case?
https://github.com/llvm/llvm-project/pull/140694
More information about the llvm-commits
mailing list