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; } 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 + +@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 +}