[PATCH] D133602: [DAGCombiner] Use HandleSDNode to keep node alive across call to getNegatedExpression.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 12:29:51 PDT 2022
craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.
getNegatedExpression can delete nodes. If the first call to
getNegatedExpression produced a node that the second call also
manages to create, it might get deleted. Use a HandleSDNode to
ensure it has a use to prevent it from being deleted.
Fixes PR57658.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133602
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/pr57658.ll
Index: llvm/test/CodeGen/X86/pr57658.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/pr57658.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+define <2 x double> @f(<2 x double> %I) {
+; CHECK-LABEL: f:
+; CHECK: # %bb.0: # %BB
+; CHECK-NEXT: movapd {{.*#+}} xmm1 = [-0.0E+0,-0.0E+0]
+; CHECK-NEXT: xorpd %xmm0, %xmm1
+; CHECK-NEXT: mulpd %xmm0, %xmm1
+; CHECK-NEXT: mulpd %xmm0, %xmm1
+; CHECK-NEXT: mulpd %xmm0, %xmm0
+; CHECK-NEXT: mulpd %xmm1, %xmm0
+; CHECK-NEXT: retq
+BB:
+ %F = fneg <2 x double> %I
+ %B3 = fmul <2 x double> %I, %F
+ %B1 = fmul <2 x double> %F, %B3
+ %B2 = fmul <2 x double> %F, %I
+ %B = fmul <2 x double> %B2, %B1
+ ret <2 x double> %B
+}
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15079,12 +15079,15 @@
TargetLowering::NegatibleCost::Expensive;
SDValue NegN0 =
TLI.getNegatedExpression(N0, DAG, LegalOperations, ForCodeSize, CostN0);
- SDValue NegN1 =
- TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
- if (NegN0 && NegN1 &&
- (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
- CostN1 == TargetLowering::NegatibleCost::Cheaper))
- return DAG.getNode(ISD::FMUL, DL, VT, NegN0, NegN1);
+ if (NegN0) {
+ HandleSDNode NegN0Handle(NegN0);
+ SDValue NegN1 =
+ TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
+ if (NegN1 &&
+ (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
+ CostN1 == TargetLowering::NegatibleCost::Cheaper))
+ return DAG.getNode(ISD::FMUL, DL, VT, NegN0, NegN1);
+ }
// fold (fmul X, (select (fcmp X > 0.0), -1.0, 1.0)) -> (fneg (fabs X))
// fold (fmul X, (select (fcmp X > 0.0), 1.0, -1.0)) -> (fabs X)
@@ -15170,12 +15173,15 @@
TargetLowering::NegatibleCost::Expensive;
SDValue NegN0 =
TLI.getNegatedExpression(N0, DAG, LegalOperations, ForCodeSize, CostN0);
- SDValue NegN1 =
- TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
- if (NegN0 && NegN1 &&
- (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
- CostN1 == TargetLowering::NegatibleCost::Cheaper))
- return DAG.getNode(ISD::FMA, DL, VT, NegN0, NegN1, N2);
+ if (NegN0) {
+ HandleSDNode NegN0Handle(NegN0);
+ SDValue NegN1 =
+ TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
+ if (NegN1 &&
+ (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
+ CostN1 == TargetLowering::NegatibleCost::Cheaper))
+ return DAG.getNode(ISD::FMA, DL, VT, NegN0, NegN1, N2);
+ }
// FIXME: use fast math flags instead of Options.UnsafeFPMath
if (Options.UnsafeFPMath) {
@@ -15473,12 +15479,15 @@
TargetLowering::NegatibleCost::Expensive;
SDValue NegN0 =
TLI.getNegatedExpression(N0, DAG, LegalOperations, ForCodeSize, CostN0);
- SDValue NegN1 =
- TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
- if (NegN0 && NegN1 &&
- (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
- CostN1 == TargetLowering::NegatibleCost::Cheaper))
- return DAG.getNode(ISD::FDIV, SDLoc(N), VT, NegN0, NegN1);
+ if (NegN0) {
+ HandleSDNode NegN0Handle(NegN0);
+ SDValue NegN1 =
+ TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize, CostN1);
+ if (NegN1 &&
+ (CostN0 == TargetLowering::NegatibleCost::Cheaper ||
+ CostN1 == TargetLowering::NegatibleCost::Cheaper))
+ return DAG.getNode(ISD::FDIV, SDLoc(N), VT, NegN0, NegN1);
+ }
return SDValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133602.459162.patch
Type: text/x-patch
Size: 3903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220909/b97eb80d/attachment.bin>
More information about the llvm-commits
mailing list