forked from OSchip/llvm-project
[SelectionDAG] Don't remove unused negated constant immediately
This reverts partial ofa2fb5446
(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.
This commit is contained in:
parent
4ce61144cb
commit
b326d4ff94
|
@ -5773,10 +5773,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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue