Skip to content

Commit 58dd59a

Browse files
authored
[RISCV] Don't run combineBinOp_VLToVWBinOp_VL until after legalize types. NFCI (#84125)
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 #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 #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 #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 718962f commit 58dd59a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13657,9 +13657,8 @@ 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;
13660+
assert(
13661+
Subtarget.getTargetLowering()->isTypeLegal(NarrowElt.getValueType()));
1366313662

1366413663
// Ensure the extension's semantic is equivalent to rvv vzext or vsext.
1366513664
if (ScalarBits != NarrowScalarBits * 2)
@@ -13732,14 +13731,11 @@ struct NodeExtensionHelper {
1373213731
}
1373313732

1373413733
/// 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();
13734+
static bool isSupportedRoot(const SDNode *Root) {
1373713735
switch (Root->getOpcode()) {
1373813736
case ISD::ADD:
1373913737
case ISD::SUB:
1374013738
case ISD::MUL: {
13741-
if (!TLI.isTypeLegal(Root->getValueType(0)))
13742-
return false;
1374313739
return Root->getValueType(0).isScalableVector();
1374413740
}
1374513741
// Vector Widening Integer Add/Sub/Mul Instructions
@@ -13756,7 +13752,7 @@ struct NodeExtensionHelper {
1375613752
case RISCVISD::FMUL_VL:
1375713753
case RISCVISD::VFWADD_W_VL:
1375813754
case RISCVISD::VFWSUB_W_VL:
13759-
return TLI.isTypeLegal(Root->getValueType(0));
13755+
return true;
1376013756
default:
1376113757
return false;
1376213758
}
@@ -13765,9 +13761,10 @@ struct NodeExtensionHelper {
1376513761
/// Build a NodeExtensionHelper for \p Root.getOperand(\p OperandIdx).
1376613762
NodeExtensionHelper(SDNode *Root, unsigned OperandIdx, SelectionDAG &DAG,
1376713763
const RISCVSubtarget &Subtarget) {
13768-
assert(isSupportedRoot(Root, DAG) && "Trying to build an helper with an "
13769-
"unsupported root");
13764+
assert(isSupportedRoot(Root) && "Trying to build an helper with an "
13765+
"unsupported root");
1377013766
assert(OperandIdx < 2 && "Requesting something else than LHS or RHS");
13767+
assert(DAG.getTargetLoweringInfo().isTypeLegal(Root->getValueType(0)));
1377113768
OrigOperand = Root->getOperand(OperandIdx);
1377213769

1377313770
unsigned Opc = Root->getOpcode();
@@ -13817,7 +13814,7 @@ struct NodeExtensionHelper {
1381713814
static std::pair<SDValue, SDValue>
1381813815
getMaskAndVL(const SDNode *Root, SelectionDAG &DAG,
1381913816
const RISCVSubtarget &Subtarget) {
13820-
assert(isSupportedRoot(Root, DAG) && "Unexpected root");
13817+
assert(isSupportedRoot(Root) && "Unexpected root");
1382113818
switch (Root->getOpcode()) {
1382213819
case ISD::ADD:
1382313820
case ISD::SUB:
@@ -14117,8 +14114,10 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1411714114
TargetLowering::DAGCombinerInfo &DCI,
1411814115
const RISCVSubtarget &Subtarget) {
1411914116
SelectionDAG &DAG = DCI.DAG;
14117+
if (DCI.isBeforeLegalize())
14118+
return SDValue();
1412014119

14121-
if (!NodeExtensionHelper::isSupportedRoot(N, DAG))
14120+
if (!NodeExtensionHelper::isSupportedRoot(N))
1412214121
return SDValue();
1412314122

1412414123
SmallVector<SDNode *> Worklist;
@@ -14129,7 +14128,7 @@ static SDValue combineBinOp_VLToVWBinOp_VL(SDNode *N,
1412914128

1413014129
while (!Worklist.empty()) {
1413114130
SDNode *Root = Worklist.pop_back_val();
14132-
if (!NodeExtensionHelper::isSupportedRoot(Root, DAG))
14131+
if (!NodeExtensionHelper::isSupportedRoot(Root))
1413314132
return SDValue();
1413414133

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

0 commit comments

Comments
 (0)