[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
github-actions[bot] wrote: @dtcxzyw (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/139356 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/139356 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
https://github.com/llvmbot updated
https://github.com/llvm/llvm-project/pull/139356
>From 2cacf46f35c8fa174a30a4b628a4b19e391a4798 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng
Date: Sat, 10 May 2025 13:14:01 +0800
Subject: [PATCH] [X86][TargetLowering] Avoid deleting temporary nodes in
`getNegatedExpression` (#139029)
In the original case, the third call to `getCheaperNegatedExpression`
deletes the SDNode returned by the first call.
Similar to 74e6030bcbcc8e628f9a99a424342a0c656456f9, this patch uses
`HandleSDNodes` to prevent nodes from being deleted by subsequent calls.
Closes https://github.com/llvm/llvm-project/issues/138944.
(cherry picked from commit 143cce72b1f50bc37363315793b80ae92d2b0ae3)
---
llvm/lib/Target/X86/X86ISelLowering.cpp | 9 -
llvm/test/CodeGen/X86/pr138982.ll | 23 +++
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/X86/pr138982.ll
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 627cef9ead7ff..4413fbb77f415 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -54147,12 +54147,19 @@ SDValue
X86TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
if (!Flags.hasNoSignedZeros())
break;
+// Because getCheaperNegatedExpression can delete nodes we need a handle to
+// keep temporary nodes alive.
+std::list Handles;
+
// This is always negatible for free but we might be able to remove some
// extra operand negations as well.
SmallVector NewOps(Op.getNumOperands(), SDValue());
-for (int i = 0; i != 3; ++i)
+for (int i = 0; i != 3; ++i) {
NewOps[i] = getCheaperNegatedExpression(
Op.getOperand(i), DAG, LegalOperations, ForCodeSize, Depth + 1);
+ if (!!NewOps[i])
+Handles.emplace_back(NewOps[i]);
+}
bool NegA = !!NewOps[0];
bool NegB = !!NewOps[1];
diff --git a/llvm/test/CodeGen/X86/pr138982.ll
b/llvm/test/CodeGen/X86/pr138982.ll
new file mode 100644
index 0..32346d823a9fe
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr138982.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64 -mattr=+fma | FileCheck %s
+
+define <4 x float> @pr138982(<4 x float> %in_vec) {
+; CHECK-LABEL: pr138982:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT:vxorps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm1
+; CHECK-NEXT:vrcpps %xmm0, %xmm2
+; CHECK-NEXT:vrcpps %xmm1, %xmm1
+; CHECK-NEXT:vxorps %xmm3, %xmm3, %xmm3
+; CHECK-NEXT:vcmpneqps %xmm0, %xmm3, %xmm0
+; CHECK-NEXT:vbroadcastss {{.*#+}} xmm4 = [1.0E+0,1.0E+0,1.0E+0,1.0E+0]
+; CHECK-NEXT:vblendvps %xmm0, %xmm1, %xmm4, %xmm0
+; CHECK-NEXT:vfnmadd231ps {{.*#+}} xmm0 = -(xmm3 * xmm2) + xmm0
+; CHECK-NEXT:retq
+entry:
+ %fneg = fneg <4 x float> %in_vec
+ %rcp = tail call <4 x float> @llvm.x86.sse.rcp.ps(<4 x float> %fneg)
+ %cmp = fcmp une <4 x float> zeroinitializer, %in_vec
+ %sel = select <4 x i1> %cmp, <4 x float> %rcp, <4 x float> splat (float
1.00e+00)
+ %fma = call nsz <4 x float> @llvm.fma.v4f32(<4 x float> %rcp, <4 x float>
zeroinitializer, <4 x float> %sel)
+ ret <4 x float> %fma
+}
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
https://github.com/RKSimon approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/139356 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/139356
Backport 143cce72b1f50bc37363315793b80ae92d2b0ae3
Requested by: @dtcxzyw
Rate limit · GitHub
body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
}
.container { margin: 50px auto; max-width: 600px; text-align: center;
padding: 0 24px; }
a { color: #0366d6; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px;
text-shadow: 0 1px 0 #fff; }
p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }
ul { list-style: none; margin: 25px 0; padding: 0; }
li { display: table-cell; font-weight: bold; width: 1%; }
.logo { display: inline-block; margin-top: 35px; }
.logo-img-2x { display: none; }
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
}
#suggestions {
margin-top: 35px;
color: #ccc;
}
#suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
}
Whoa there!
You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
llvmbot wrote:
@llvm/pr-subscribers-backend-x86
Author: None (llvmbot)
Changes
Backport 143cce72b1f50bc37363315793b80ae92d2b0ae3
Requested by: @dtcxzyw
---
Full diff: https://github.com/llvm/llvm-project/pull/139356.diff
2 Files Affected:
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+8-1)
- (added) llvm/test/CodeGen/X86/pr138982.ll (+23)
``diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 627cef9ead7ff..4413fbb77f415 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -54147,12 +54147,19 @@ SDValue
X86TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
if (!Flags.hasNoSignedZeros())
break;
+// Because getCheaperNegatedExpression can delete nodes we need a handle to
+// keep temporary nodes alive.
+std::list Handles;
+
// This is always negatible for free but we might be able to remove some
// extra operand negations as well.
SmallVector NewOps(Op.getNumOperands(), SDValue());
-for (int i = 0; i != 3; ++i)
+for (int i = 0; i != 3; ++i) {
NewOps[i] = getCheaperNegatedExpression(
Op.getOperand(i), DAG, LegalOperations, ForCodeSize, Depth + 1);
+ if (!!NewOps[i])
+Handles.emplace_back(NewOps[i]);
+}
bool NegA = !!NewOps[0];
bool NegB = !!NewOps[1];
diff --git a/llvm/test/CodeGen/X86/pr138982.ll
b/llvm/test/CodeGen/X86/pr138982.ll
new file mode 100644
index 0..32346d823a9fe
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr138982.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64 -mattr=+fma | FileCheck %s
+
+define <4 x float> @pr138982(<4 x float> %in_vec) {
+; CHECK-LABEL: pr138982:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT:vxorps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm1
+; CHECK-NEXT:vrcpps %xmm0, %xmm2
+; CHECK-NEXT:vrcpps %xmm1, %xmm1
+; CHECK-NEXT:vxorps %xmm3, %xmm3, %xmm3
+; CHECK-NEXT:vcmpneqps %xmm0, %xmm3, %xmm0
+; CHECK-NEXT:vbroadcastss {{.*#+}} xmm4 = [1.0E+0,1.0E+0,1.0E+0,1.0E+0]
+; CHECK-NEXT:vblendvps %xmm0, %xmm1, %xmm4, %xmm0
+; CHECK-NEXT:vfnmadd231ps {{.*#+}} xmm0 = -(xmm3 * xmm2) + xmm0
+; CHECK-NEXT:retq
+entry:
+ %fneg = fneg <4 x float> %in_vec
+ %rcp = tail call <4 x float> @llvm.x86.sse.rcp.ps(<4 x float> %fneg)
+ %cmp = fcmp une <4 x float> zeroinitializer, %in_vec
+ %sel = select <4 x i1> %cmp, <4 x float> %rcp, <4 x float> splat (float
1.00e+00)
+ %fma = call nsz <4 x float> @llvm.fma.v4f32(<4 x float> %rcp, <4 x float>
zeroinitializer, <4 x float> %sel)
+ ret <4 x float> %fma
+}
``
https://github.com/llvm/llvm-project/pull/139356
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/139356 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [X86][TargetLowering] Avoid deleting temporary nodes in `getNegatedExpression` (#139029) (PR #139356)
llvmbot wrote: @topperc What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/139356 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
