[llvm] [DAGCombiner] visitFREEZE: Early exit when N is deleted (PR #128161)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 21 08:04:14 PST 2025
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/128161
>From 530460ab297a35b72cdbadfbdf624e114b5cda88 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 21 Feb 2025 18:50:00 +0800
Subject: [PATCH 1/2] [DAGCombiner] visitFREEZE: Early exit when N has been
deleted
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 8 ++---
llvm/test/CodeGen/X86/pr128143.ll | 32 +++++++++++++++++++
2 files changed, 36 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/pr128143.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index b07f3814d9d2d..3bd683fcce1e2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -16158,11 +16158,11 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
DAG.UpdateNodeOperands(FrozenMaybePoisonOperand.getNode(),
MaybePoisonOperand);
}
- }
- // This node has been merged with another.
- if (N->getOpcode() == ISD::DELETED_NODE)
- return SDValue(N, 0);
+ // This node has been merged with another.
+ if (N->getOpcode() == ISD::DELETED_NODE)
+ return SDValue(N, 0);
+ }
// The whole node may have been updated, so the value we were holding
// may no longer be valid. Re-fetch the operand we're `freeze`ing.
diff --git a/llvm/test/CodeGen/X86/pr128143.ll b/llvm/test/CodeGen/X86/pr128143.ll
new file mode 100644
index 0000000000000..2517ad9ebcb6b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr128143.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
+
+ at g_1 = external global i8
+ at g_2 = external global i8
+
+; Make sure we don't crash on this test.
+
+define i1 @test(i1 %cmp1, i32 %x) {
+; CHECK-LABEL: test:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: movq g_2 at GOTPCREL(%rip), %rcx
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: cmpq %rcx, g_1 at GOTPCREL(%rip)
+; CHECK-NEXT: setne %al
+; CHECK-NEXT: cmpl %eax, %esi
+; CHECK-NEXT: setb %cl
+; CHECK-NEXT: orb %cl, %al
+; CHECK-NEXT: andb %dil, %al
+; CHECK-NEXT: # kill: def $al killed $al killed $eax
+; CHECK-NEXT: retq
+entry:
+ %cmp2 = icmp ne ptr @g_1, @g_2
+ %fr = freeze ptr @g_1
+ %cmp3 = icmp ne ptr %fr, @g_2
+ %ext1 = zext i1 %cmp3 to i32
+ %sel1 = select i1 %cmp1, i1 %cmp2, i1 false
+ %cmp4 = icmp ult i32 %x, %ext1
+ %sel3 = select i1 %cmp1, i1 %cmp4, i1 false
+ %or = or i1 %sel1, %sel3
+ ret i1 %or
+}
>From 3a9561b1d0eedbb0b90d0a7458c9412f66d6883b Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sat, 22 Feb 2025 00:03:48 +0800
Subject: [PATCH 2/2] [DAGCombiner] Add an assertion.
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 3bd683fcce1e2..a83be13ebff2b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -16164,6 +16164,8 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
return SDValue(N, 0);
}
+ assert(N->getOpcode() != ISD::DELETED_NODE && "Node was deleted!");
+
// The whole node may have been updated, so the value we were holding
// may no longer be valid. Re-fetch the operand we're `freeze`ing.
N0 = N->getOperand(0);
More information about the llvm-commits
mailing list