[llvm] add narrowExtractedVectorUnaryOp to simplify cast nodes (PR #87977)
Vedant Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 03:10:03 PDT 2024
================
@@ -24083,6 +24083,55 @@ static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
BinOp->getFlags());
}
+/// If we are extracting a subvector produced by a wide unary operator try
+/// to use a narrow unary operator and/or avoid extraction.
+static SDValue narrowExtractedVectorUnaryOp(SDNode *Extract, SelectionDAG &DAG,
+ bool LegalOperations) {
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ SDValue UnaryOp = Extract->getOperand(0);
+ unsigned UnaryOpcode = UnaryOp.getOpcode();
+
+ if (UnaryOpcode != ISD::FP_TO_SINT || UnaryOp->getNumValues() != 1)
+ return SDValue();
+
+ // The extract index must be a constant, so we can map it to a concat operand.
+ auto *ExtractIndexC = dyn_cast<ConstantSDNode>(Extract->getOperand(1));
+ if (!ExtractIndexC)
+ return SDValue();
+
+ EVT WideUVT = UnaryOp.getValueType();
+ if (!WideUVT.isFixedLengthVector())
+ return SDValue();
+
+ EVT VT = Extract->getValueType(0);
+ unsigned ExtractIndex = ExtractIndexC->getZExtValue();
+ assert(ExtractIndex % VT.getVectorNumElements() == 0 &&
+ "Extract index is not a multiple of the vector length.");
+
+ // Bail out if this is not a proper multiple width extraction.
+ unsigned WideWidth = WideUVT.getSizeInBits();
+ unsigned NarrowWidth = VT.getSizeInBits();
+ if (WideWidth % NarrowWidth != 0)
+ return SDValue();
+
+ unsigned NarrowingRatio = WideWidth / NarrowWidth;
+ unsigned WideNumElts = WideUVT.getVectorNumElements();
+
+ // Bail out if the target does not support a narrower version of the unaryop.
+ EVT NarrowUVT = EVT::getVectorVT(*DAG.getContext(), WideUVT.getScalarType(),
+ WideNumElts / NarrowingRatio);
+ if (!TLI.isOperationLegalOrCustomOrPromote(UnaryOpcode, NarrowUVT,
+ LegalOperations))
+ return SDValue();
+
----------------
vedantparanjape-amd wrote:
Ah, I see. so there should a extract_subvec before fp_to_sint as well. I thought such a pattern would be already handled.
https://github.com/llvm/llvm-project/pull/87977
More information about the llvm-commits
mailing list