Skip to content

Commit 2508ef0

Browse files
committed
[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
1 parent 5f13d6c commit 2508ef0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -5773,8 +5773,10 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
57735773

57745774
// If we already have the use of the negated floating constant, it is free
57755775
// to negate it even it has multiple uses.
5776-
if (!Op.hasOneUse() && CFP.use_empty())
5776+
if (!Op.hasOneUse() && CFP.use_empty()) {
5777+
RemoveDeadNode(CFP);
57775778
break;
5779+
}
57785780
Cost = NegatibleCost::Neutral;
57795781
return CFP;
57805782
}

llvm/test/CodeGen/X86/pr47517.ll

+28
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)