Skip to content

Commit 88e17a8

Browse files
ecneliseszmodem
authored andcommitted
[SelectionDAG] Remove unused FP constant in getNegatedExpression
960cbc5 immediately removes nodes that won't be used to avoid compilation time explosion. This patch adds the removal to constants to fix PR47517. Reviewed By: RKSimon, steven.zhang Differential Revision: https://reviews.llvm.org/D87614 (cherry picked from commit 2508ef0)
1 parent be31896 commit 88e17a8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5751,8 +5751,10 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
57515751

57525752
// If we already have the use of the negated floating constant, it is free
57535753
// to negate it even it has multiple uses.
5754-
if (!Op.hasOneUse() && CFP.use_empty())
5754+
if (!Op.hasOneUse() && CFP.use_empty()) {
5755+
RemoveDeadNode(CFP);
57555756
break;
5757+
}
57565758
Cost = NegatibleCost::Neutral;
57575759
return CFP;
57585760
}

llvm/test/CodeGen/X86/pr47517.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple x86_64 < %s | FileCheck %s
3+
4+
; To ensure unused floating point constant is removed in negation
5+
define float @test(float %src, float* %p) {
6+
; CHECK-LABEL: test:
7+
; CHECK: # %bb.0: # %entry
8+
; CHECK-NEXT: movq $0, (%rdi)
9+
; CHECK-NEXT: xorps %xmm0, %xmm0
10+
; CHECK-NEXT: retq
11+
entry:
12+
%a0 = getelementptr inbounds float, float* %p, i32 0
13+
%a1 = getelementptr inbounds float, float* %p, i32 1
14+
store float 0.000000e+00, float* %a0
15+
store float 0.000000e+00, float* %a1
16+
%zero = load float, float* %a0
17+
%fmul1 = fmul fast float %zero, %src
18+
%fadd1 = fadd fast float %fmul1, %zero
19+
%fmul2 = fmul fast float %fadd1, 2.000000e+00
20+
%fmul3 = fmul fast float %fmul2, %fmul2
21+
%fmul4 = fmul fast float %fmul2, 2.000000e+00
22+
%fadd2 = fadd fast float %fmul4, -3.000000e+00
23+
%fmul5 = fmul fast float %fadd2, %fmul2
24+
%fadd3 = fadd fast float %fmul2, %src
25+
%fadd4 = fadd fast float %fadd3, %fmul5
26+
%fmul6 = fmul fast float %fmul3, %fadd4
27+
ret float %fmul6
28+
}

0 commit comments

Comments
 (0)