[llvm] e16ec9b - [SelectionDAG] Do not build illegal nodes with users (#108573)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 02:02:45 PDT 2024
Author: ErikHogeman
Date: 2024-09-16T10:02:42+01:00
New Revision: e16ec9b45e4a8fd3fdc67338ea9c77457460a25a
URL: https://github.com/llvm/llvm-project/commit/e16ec9b45e4a8fd3fdc67338ea9c77457460a25a
DIFF: https://github.com/llvm/llvm-project/commit/e16ec9b45e4a8fd3fdc67338ea9c77457460a25a.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 29505f444b7650..44ec6f7cab145a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -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);
}
More information about the llvm-commits
mailing list