[llvm] [SelectionDAG][X86] Fix the assertion failure in Release build after #91747 (PR #93434)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Sun May 26 20:00:38 PDT 2024
https://github.com/KanRobert updated https://github.com/llvm/llvm-project/pull/93434
>From 11425bd85fa77c3118b0262e22f72c96d0b7b7ad Mon Sep 17 00:00:00 2001
From: Shengchen Kan <shengchen.kan at intel.com>
Date: Mon, 27 May 2024 10:46:01 +0800
Subject: [PATCH 1/2] [SelectionDAG][X86] Fix the assertion failure in Release
build after #91747
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.
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 5 ++++-
llvm/lib/Target/X86/X86ISelLowering.cpp | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index c7aeb0633e4ba..93d866384b482 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1801,8 +1801,11 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
if (N->getNumValues() == RV->getNumValues())
DAG.ReplaceAllUsesWith(N, RV.getNode());
- else
+ else {
+ assert(N->getValueType(0) == RV.getValueType() &&
+ N->getNumValues() == 1 && "Type mismatch");
DAG.ReplaceAllUsesWith(N, &RV);
+ }
// Push the new node and any users onto the worklist. Omit this if the
// new node is the EntryToken (e.g. if a store managed to get optimized
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 7d90296a3eea6..09284839b9680 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -49253,8 +49253,9 @@ static SDValue combineX86SubCmpForFlags(SDNode *N, SDValue Flag,
return SDValue();
SDValue X = SetCC.getOperand(1);
- // Replace API is called manually here b/c the number of results may change.
- DAG.ReplaceAllUsesOfValueWith(Flag, X);
+ // sub has two results while X only have one. DAG combine assumes the value type match.
+ if (N->getNumValues() > 1)
+ X = DAG.getMergeValues({N->getOperand(0), X}, SDLoc(N));
SDValue CCN = SetCC.getOperand(0);
X86::CondCode CC =
>From 0c0e2e85989830d4f0cd3d3c8ae056fb40c1a1f8 Mon Sep 17 00:00:00 2001
From: Shengchen Kan <shengchen.kan at intel.com>
Date: Mon, 27 May 2024 11:00:25 +0800
Subject: [PATCH 2/2] format code
---
llvm/lib/Target/X86/X86ISelLowering.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 09284839b9680..3ccb8d6a0c29e 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -49253,7 +49253,8 @@ static SDValue combineX86SubCmpForFlags(SDNode *N, SDValue Flag,
return SDValue();
SDValue X = SetCC.getOperand(1);
- // sub has two results while X only have one. DAG combine assumes the value type match.
+ // sub has two results while X only have one. DAG combine assumes the value
+ // type matches.
if (N->getNumValues() > 1)
X = DAG.getMergeValues({N->getOperand(0), X}, SDLoc(N));
More information about the llvm-commits
mailing list