[llvm] [SelectionDAG] Fix the assertion failure in Release build after #91747 (PR #93416)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Sun May 26 08:30:25 PDT 2024
https://github.com/KanRobert created https://github.com/llvm/llvm-project/pull/93416
In #91747, we change the SDNode from `X86ISD::SUB` (FROM) to `X86ISD::CCMP` (TO) in the DAGCombine. The value type of X86ISD::SUB can be `i8, i32` while the value type of X86ISD::CCMP is `i32`.
That means the `SDValue(FROM, 0)` is unused and may be removed. However, `transferDbgValues` assumes the value is not null, which is called by `ReplaceAllUsesWith(SDNode *, const SDValue *)`. So we need to check if the value has any use before calling the function.
Note: We already have same check in `ReplaceAllUsesWith(SDNode *, SDNode *)`.
This fix the error
```
SelectionDAG.cpp:10942: void
llvm::SelectionDAG::transferDbgValues(llvm::SDValue, llvm::SDValue,
unsigned int, unsigned int, bool): Assertion `FromNode && ToNode &&
"Can't modify dbg values"' failed.
```
for tests
llvm/test/CodeGen/X86/apx/ccmp.ll
llvm/test/CodeGen/X86/apx/ctest.ll
in Release build when LLVM_ENABLE_ASSERTIONS is on.
>From 0789b4dbc9af33d3ec3e4f0f5456ae47b9df6ca7 Mon Sep 17 00:00:00 2001
From: Shengchen Kan <shengchen.kan at intel.com>
Date: Sun, 26 May 2024 23:06:56 +0800
Subject: [PATCH] [SelectionDAG] Fix the assertion failure in Release build
after #91747
In #91747, we change the SDNode from `X86ISD::SUB` (FROM) to
`X86ISD::CCMP` (TO) in the DAGCombine. The value type of X86ISD::SUB
can be `i8, i32` while the value type of X86ISD::CCMP is `i32`.
That means the `SDValue(FROM, 0)` is unused and may be removed.
However, `transferDbgValues` assumes the value is not null, which is
called by `ReplaceAllUsesWith(SDNode *, const SDValue *)`.
So we need to check if the value has any use before calling the function.
Note: We already have same check in `ReplaceAllUsesWith(SDNode *, SDNode *)`.
This fix the error
```
SelectionDAG.cpp:10942: void
llvm::SelectionDAG::transferDbgValues(llvm::SDValue, llvm::SDValue,
unsigned int, unsigned int, bool): Assertion `FromNode && ToNode &&
"Can't modify dbg values"' failed.
```
for tests
llvm/test/CodeGen/X86/apx/ccmp.ll
llvm/test/CodeGen/X86/apx/ctest.ll
in Release build when LLVM_ENABLE_ASSERTIONS is on.
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index b05649c6ce955..f21b17102bde5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -11293,10 +11293,12 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
return ReplaceAllUsesWith(SDValue(From, 0), To[0]);
for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) {
- // Preserve Debug Info.
- transferDbgValues(SDValue(From, i), To[i]);
- // Preserve extra info.
- copyExtraInfo(From, To[i].getNode());
+ if (From->hasAnyUseOfValue(i)) {
+ // Preserve Debug Info.
+ transferDbgValues(SDValue(From, i), To[i]);
+ // Preserve extra info.
+ copyExtraInfo(From, To[i].getNode());
+ }
}
// Iterate over just the existing users of From. See the comments in
More information about the llvm-commits
mailing list