[llvm] r262212 - [InstSimplify] fsub 0.0, (fsub -0.0, X) ==> X is only safe if signed zeros are ignored.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 29 03:12:23 PST 2016
Author: d0k
Date: Mon Feb 29 05:12:23 2016
New Revision: 262212
URL: http://llvm.org/viewvc/llvm-project?rev=262212&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=262212&r1=262211&r2=262212&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Feb 29 05:12:23 2016
@@ -833,14 +833,15 @@ static Value *SimplifyFSubInst(Value *Op
(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)
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll?rev=262212&r1=262211&r2=262212&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Mon Feb 29 05:12:23 2016
@@ -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) {
More information about the llvm-commits
mailing list