Skip to content

Commit

Permalink
[SelectionDAG] Do not build illegal nodes with users (#108573)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ErikHogeman authored Sep 16, 2024
1 parent 57b50a9 commit e16ec9b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6799,14 +6799,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
// Constant fold the scalar operands.
SDValue ScalarResult = getNode(Opcode, DL, SVT, ScalarOps, Flags);

// Legalize the (integer) scalar constant if necessary.
if (LegalSVT != SVT)
ScalarResult = getNode(ExtendCode, DL, LegalSVT, ScalarResult);

// Scalar folding only succeeded if the result is a constant or UNDEF.
if (!ScalarResult.isUndef() && ScalarResult.getOpcode() != ISD::Constant &&
ScalarResult.getOpcode() != ISD::ConstantFP)
return SDValue();

// Legalize the (integer) scalar constant if necessary. We only do
// this once we know the folding succeeded, since otherwise we would
// get a node with illegal type which has a user.
if (LegalSVT != SVT)
ScalarResult = getNode(ExtendCode, DL, LegalSVT, ScalarResult);

ScalarResults.push_back(ScalarResult);
}

Expand Down

0 comments on commit e16ec9b

Please sign in to comment.