Skip to content

Commit ea2bc3a

Browse files
committed
[RISCV] Don't run combineBinOp_VLToVWBinOp_VL until after legalize types. NFCI
I noticed this from a discrepancy in fillUpExtensionSupport between how we apparently need to check for legal types for ISD::{ZERO,SIGN}_EXTEND, but we don't need to for RISCVISD::V{Z,S}EXT_VL. Prior to llvm#72340, combineBinOp_VLToVWBinOp_VL only ran after type legalization because it only operated on _VL nodes. _VL nodes are only emitted during op legalization, which takes place **after** type legalization, which is presumably why the existing code didn't need to check for legal types. After llvm#72340 we now handle generic ops like ISD::ADD that exist before op legalization and thus **before** type legalization. This meant that we needed to add extra checks that the narrow type was legal in llvm#76785. I think the easiest thing to do here is to just maintain the invariant that the types are legal and only run the combine after type legalization.
1 parent f1aa783 commit ea2bc3a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13657,10 +13657,6 @@ struct NodeExtensionHelper {
1365713657
unsigned ScalarBits = VT.getScalarSizeInBits();
1365813658
unsigned NarrowScalarBits = NarrowVT.getScalarSizeInBits();
1365913659

13660-
// Ensure the narrowing element type is legal
13661-
if (!Subtarget.getTargetLowering()->isTypeLegal(NarrowElt.getValueType()))
13662-
break;
13663-
1366413660
// Ensure the extension's semantic is equivalent to rvv vzext or vsext.
1366513661
if (ScalarBits != NarrowScalarBits * 2)
1366613662
break;
@@ -13732,14 +13728,11 @@ struct NodeExtensionHelper {
1373213728
}
1373313729

1373413730
/// Check if \p Root supports any extension folding combines.
13735-
static bool isSupportedRoot(const SDNode *Root, const SelectionDAG &DAG) {
13736-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
13731+
static bool isSupportedRoot(const SDNode *Root) {
1373713732
switch (Root->getOpcode()) {
1373813733
case ISD::ADD:
1373913734
case ISD::SUB:
1374013735
case ISD::MUL: {
13741-
if (!TLI.isTypeLegal(Root->getValueType(0)))
13742-
return false;
1374313736
return Root->getValueType(0).isScalableVector();
1374413737
}
1374513738
// Vector Widening Integer Add/Sub/Mul Instructions
@@ -13756,7 +13749,7 @@ struct NodeExtensionHelper {
1375613749
case RISCVISD::FMUL_VL:
1375713750
case RISCVISD::VFWADD_W_VL:
1375813751
case RISCVISD::VFWSUB_W_VL:
13759-
return TLI.isTypeLegal(Root->getValueType(0));
13752+
return true;
1376013753
default:
1376113754
return false;
1376213755
}
@@ -13765,9 +13758,10 @@ struct NodeExtensionHelper {
1376513758
/// Build a NodeExtensionHelper for \p Root.getOperand(\p OperandIdx).
1376613759
NodeExtensionHelper(SDNode *Root, unsigned OperandIdx, SelectionDAG &DAG,
1376713760
const RISCVSubtarget &Subtarget) {
13768-
assert(isSupportedRoot(Root, DAG) && "Trying to build an helper with an "
13769-
"unsupported root");
13761+
assert(isSupportedRoot(Root) && "Trying to build an helper with an "
13762+
"unsupported root");
1377013763
assert(OperandIdx < 2 && "Requesting something else than LHS or RHS");
13764+
assert(DAG.getTargetLoweringInfo().isTypeLegal(Root->getValueType(0)));
1377113765
OrigOperand = Root->getOperand(OperandIdx);
1377213766

1377313767
unsigned Opc = Root->getOpcode();
@@ -13817,7 +13811,7 @@ struct NodeExtensionHelper {
1381713811
static std::pair<SDValue, SDValue>
1381813812
getMaskAndVL(const SDNode *Root, SelectionDAG &DAG,
1381913813
const RISCVSubtarget &Subtarget) {
13820-
assert(isSupportedRoot(Root, DAG) && "Unexpected root");
13814+
assert(isSupportedRoot(Root) && "Unexpected root");
1382113815
switch (Root->getOpcode()) {
1382213816
case ISD::ADD:
1382313817
case ISD::SUB:
@@ -14117,8 +14111,10 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1411714111
TargetLowering::DAGCombinerInfo &DCI,
1411814112
const RISCVSubtarget &Subtarget) {
1411914113
SelectionDAG &DAG = DCI.DAG;
14114+
if (DCI.isBeforeLegalize())
14115+
return SDValue();
1412014116

14121-
if (!NodeExtensionHelper::isSupportedRoot(N, DAG))
14117+
if (!NodeExtensionHelper::isSupportedRoot(N))
1412214118
return SDValue();
1412314119

1412414120
SmallVector<SDNode *> Worklist;
@@ -14129,7 +14125,7 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1412914125

1413014126
while (!Worklist.empty()) {
1413114127
SDNode *Root = Worklist.pop_back_val();
14132-
if (!NodeExtensionHelper::isSupportedRoot(Root, DAG))
14128+
if (!NodeExtensionHelper::isSupportedRoot(Root))
1413314129
return SDValue();
1413414130

1413514131
NodeExtensionHelper LHS(N, 0, DAG, Subtarget);

0 commit comments

Comments
 (0)