Skip to content

Commit e16ec9b

Browse files
authored
[SelectionDAG] Do not build illegal nodes with users (#108573)
When we build a node with illegal type which has a user, it's possible that it can end up being processed by the DAG combiner later before it's removed, which can trigger an assert expecting the types to be legalized already.
1 parent 57b50a9 commit e16ec9b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6799,14 +6799,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
67996799
// Constant fold the scalar operands.
68006800
SDValue ScalarResult = getNode(Opcode, DL, SVT, ScalarOps, Flags);
68016801

6802-
// Legalize the (integer) scalar constant if necessary.
6803-
if (LegalSVT != SVT)
6804-
ScalarResult = getNode(ExtendCode, DL, LegalSVT, ScalarResult);
6805-
68066802
// Scalar folding only succeeded if the result is a constant or UNDEF.
68076803
if (!ScalarResult.isUndef() && ScalarResult.getOpcode() != ISD::Constant &&
68086804
ScalarResult.getOpcode() != ISD::ConstantFP)
68096805
return SDValue();
6806+
6807+
// Legalize the (integer) scalar constant if necessary. We only do
6808+
// this once we know the folding succeeded, since otherwise we would
6809+
// get a node with illegal type which has a user.
6810+
if (LegalSVT != SVT)
6811+
ScalarResult = getNode(ExtendCode, DL, LegalSVT, ScalarResult);
6812+
68106813
ScalarResults.push_back(ScalarResult);
68116814
}
68126815

0 commit comments

Comments
 (0)