[PATCH] D87614: [SelectionDAG] Remove unused FP constant in getNegatedExpression

Qiu Chaofan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 07:52:20 PDT 2020


qiucf created this revision.
qiucf added reviewers: RKSimon, spatel, efriedma, hans, steven.zhang, uabelho.
Herald added subscribers: llvm-commits, ecnelises, hiraditya.
Herald added a project: LLVM.
qiucf requested review of this revision.

960cbc53 <https://reviews.llvm.org/rG960cbc53ca170c8c605bf83fa63b49ab27a56f65> immediately removes nodes that won't be used to avoid compilation time explosion. This patch adds the removal to constants to fix PR47517.


https://reviews.llvm.org/D87614

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/test/CodeGen/X86/pr47517.ll


Index: llvm/test/CodeGen/X86/pr47517.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/pr47517.ll
@@ -0,0 +1,33 @@
+; RUN: llc -mtriple x86_64 < %s
+
+ at a = external global { float, float }
+
+; To ensure unused floating point constant is removed in negation
+define void @test() {
+entry:
+  br label %for.cond
+
+for.cond:
+  %b.0 = phi i16 [ undef, %entry ], [ %conv87, %for.cond ]
+  store float 0.000000e+00, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  store float 0.000000e+00, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 1)
+  %a.real3 = load float, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  %conv = sitofp i16 %b.0 to float
+  %mul_ac = fmul fast float %a.real3, %conv
+  %add.r = fadd fast float %mul_ac, %a.real3
+  store float %add.r, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  %a.real8 = load float, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  %factor = fmul fast float %a.real8, 2.000000e+00
+  store float %factor, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  store float 0.000000e+00, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 1)
+  %a.real14 = load float, float* getelementptr inbounds ({ float, float }, { float, float }* @a, i16 0, i32 0)
+  %mul_ac18 = fmul fast float %a.real14, %a.real14
+  %mul_ac40 = fmul fast float %a.real14, 2.000000e+00
+  %reass.add = fadd fast float %mul_ac40, -3.000000e+00
+  %reass.mul = fmul fast float %reass.add, %a.real14
+  %0 = fadd fast float %a.real14, %conv
+  %sub.r71 = fadd fast float %0, %reass.mul
+  %mul_ac73 = fmul fast float %mul_ac18, %sub.r71
+  %conv87 = fptosi float %mul_ac73 to i16
+  br label %for.cond
+}
Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5762,8 +5762,10 @@
 
     // If we already have the use of the negated floating constant, it is free
     // to negate it even it has multiple uses.
-    if (!Op.hasOneUse() && CFP.use_empty())
+    if (!Op.hasOneUse() && CFP.use_empty()) {
+      RemoveDeadNode(CFP);
       break;
+    }
     Cost = NegatibleCost::Neutral;
     return CFP;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87614.291578.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200914/49d34e0f/attachment.bin>


More information about the llvm-commits mailing list