[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:40 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);
----------------
JanekvO wrote:
```suggestion
return Src.getOperand(0);
```
Just my $0.02 but: I know `PeekSrc == Src` given the if statement and ternary assignment of `PeekSrc`, but now it looks like there's an explicit reason as to why `PeekSrc.getOperand(0)` was used instead of the `Src` equivalent.
https://github.com/llvm/llvm-project/pull/140694
More information about the llvm-commits
mailing list