Skip to content

Commit 0789b4d

Browse files
committed
[SelectionDAG] Fix the assertion failure in Release build after llvm#91747
In llvm#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.
1 parent 331eb8a commit 0789b4d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11293,10 +11293,12 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
1129311293
return ReplaceAllUsesWith(SDValue(From, 0), To[0]);
1129411294

1129511295
for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) {
11296-
// Preserve Debug Info.
11297-
transferDbgValues(SDValue(From, i), To[i]);
11298-
// Preserve extra info.
11299-
copyExtraInfo(From, To[i].getNode());
11296+
if (From->hasAnyUseOfValue(i)) {
11297+
// Preserve Debug Info.
11298+
transferDbgValues(SDValue(From, i), To[i]);
11299+
// Preserve extra info.
11300+
copyExtraInfo(From, To[i].getNode());
11301+
}
1130011302
}
1130111303

1130211304
// Iterate over just the existing users of From. See the comments in

0 commit comments

Comments
 (0)