Skip to content

Commit eeb2f72

Browse files
authored
[SelectionDAG][X86] Fix the assertion failure in Release build after #91747 (#93434)
In #91747, we changed 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. This breaks the assumption that the value type should match after the combine and triggers 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. ``` when running tests llvm/test/CodeGen/X86/apx/ccmp.ll llvm/test/CodeGen/X86/apx/ctest.ll in Release build when LLVM_ENABLE_ASSERTIONS is on. In this patch, we fix it by creating a merged value.
1 parent bafda89 commit eeb2f72

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,8 +1801,11 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
18011801

18021802
if (N->getNumValues() == RV->getNumValues())
18031803
DAG.ReplaceAllUsesWith(N, RV.getNode());
1804-
else
1804+
else {
1805+
assert(N->getValueType(0) == RV.getValueType() &&
1806+
N->getNumValues() == 1 && "Type mismatch");
18051807
DAG.ReplaceAllUsesWith(N, &RV);
1808+
}
18061809

18071810
// Push the new node and any users onto the worklist. Omit this if the
18081811
// new node is the EntryToken (e.g. if a store managed to get optimized

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49253,8 +49253,10 @@ static SDValue combineX86SubCmpForFlags(SDNode *N, SDValue Flag,
4925349253
return SDValue();
4925449254

4925549255
SDValue X = SetCC.getOperand(1);
49256-
// Replace API is called manually here b/c the number of results may change.
49257-
DAG.ReplaceAllUsesOfValueWith(Flag, X);
49256+
// sub has two results while X only have one. DAG combine assumes the value
49257+
// type matches.
49258+
if (N->getOpcode() == X86ISD::SUB)
49259+
X = DAG.getMergeValues({N->getOperand(0), X}, SDLoc(N));
4925849260

4925949261
SDValue CCN = SetCC.getOperand(0);
4926049262
X86::CondCode CC =

0 commit comments

Comments
 (0)