1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[SelectionDAG] Don't remove unused negated constant immediately

This reverts partial of a2fb5446 (actually, 2508ef01) about removing
negated FP constant immediately if it has no uses. However, as discussed
in bug 47517, there're cases when NegX is folded into constant from
other places while NegY is removed by that line of code and NegX is
equal to NegY. In these cases, NegX is deleted before used and crash
happens. So revert the code and add necessary test case.

(cherry picked from commit b326d4ff946d2061a566a3fcce9f33b484759fe0)
This commit is contained in:
Qiu Chaofan 2020-10-06 00:45:24 +08:00 committed by Hans Wennborg
parent 67f791eb79
commit ce106590bf
2 changed files with 14 additions and 3 deletions

View File

@ -5751,10 +5751,8 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
// 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()) {
RemoveDeadNode(CFP);
if (!Op.hasOneUse() && CFP.use_empty())
break;
}
Cost = NegatibleCost::Neutral;
return CFP;
}

View File

@ -26,3 +26,16 @@ entry:
%fmul6 = fmul fast float %fmul3, %fadd4
ret float %fmul6
}
; To ensure negated result will not be removed when NegX=NegY and
; NegX is needed
define float @test2(float %x, float %y) {
%add = fadd fast float %x, 750.0
%sub = fsub fast float %x, %add
%mul = fmul fast float %sub, %sub
%mul2 = fmul fast float %mul, %sub
%add2 = fadd fast float %mul2, 1.0
%add3 = fadd fast float %mul2, %add2
%mul3 = fmul fast float %y, %add3
ret float %mul3
}