forked from OSchip/llvm-project
[InstSimplify] fsub 0.0, (fsub -0.0, X) ==> X is only safe if signed zeros are ignored.
Only allow fsub -0.0, (fsub -0.0, X) ==> X without nsz. PR26746. llvm-svn: 262212
This commit is contained in:
parent
27ba83fd45
commit
f5b2a47ac6
|
@ -833,14 +833,15 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
|
|||
(FMF.noSignedZeros() || CannotBeNegativeZero(Op0)))
|
||||
return Op0;
|
||||
|
||||
// fsub 0, (fsub -0.0, X) ==> X
|
||||
// fsub -0.0, (fsub -0.0, X) ==> X
|
||||
Value *X;
|
||||
if (match(Op0, m_AnyZero())) {
|
||||
if (match(Op1, m_FSub(m_NegZero(), m_Value(X))))
|
||||
return X;
|
||||
if (FMF.noSignedZeros() && match(Op1, m_FSub(m_AnyZero(), m_Value(X))))
|
||||
return X;
|
||||
}
|
||||
if (match(Op0, m_NegZero()) && match(Op1, m_FSub(m_NegZero(), m_Value(X))))
|
||||
return X;
|
||||
|
||||
// fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored.
|
||||
if (FMF.noSignedZeros() && match(Op0, m_NegZero()) &&
|
||||
match(Op1, m_FSub(m_AnyZero(), m_Value(X))))
|
||||
return X;
|
||||
|
||||
// fsub nnan x, x ==> 0.0
|
||||
if (FMF.noNaNs() && Op0 == Op1)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
; RUN: opt < %s -instsimplify -S | FileCheck %s
|
||||
|
||||
; fsub 0, (fsub 0, X) ==> X
|
||||
; CHECK-LABEL: @fsub_0_0_x(
|
||||
define float @fsub_0_0_x(float %a) {
|
||||
; fsub -0.0, (fsub -0.0, X) ==> X
|
||||
; CHECK-LABEL: @fsub_-0_-0_x(
|
||||
define float @fsub_-0_-0_x(float %a) {
|
||||
%t1 = fsub float -0.0, %a
|
||||
%ret = fsub float -0.0, %t1
|
||||
|
||||
|
@ -10,6 +10,26 @@ define float @fsub_0_0_x(float %a) {
|
|||
ret float %ret
|
||||
}
|
||||
|
||||
; fsub 0.0, (fsub -0.0, X) != X
|
||||
; CHECK-LABEL: @fsub_0_-0_x(
|
||||
define float @fsub_0_-0_x(float %a) {
|
||||
%t1 = fsub float 0.0, %a
|
||||
%ret = fsub float -0.0, %t1
|
||||
|
||||
; CHECK-NOT: ret float %a
|
||||
ret float %ret
|
||||
}
|
||||
|
||||
; fsub -0.0, (fsub 0.0, X) != X
|
||||
; CHECK-LABEL: @fsub_-0_0_x(
|
||||
define float @fsub_-0_0_x(float %a) {
|
||||
%t1 = fsub float -0.0, %a
|
||||
%ret = fsub float 0.0, %t1
|
||||
|
||||
; CHECK-NOT: ret float %a
|
||||
ret float %ret
|
||||
}
|
||||
|
||||
; fsub X, 0 ==> X
|
||||
; CHECK-LABEL: @fsub_x_0(
|
||||
define float @fsub_x_0(float %a) {
|
||||
|
|
Loading…
Reference in New Issue