OSDN Git Service

[InstSimplify] Add unary fneg to `fsub 0.0, (fneg X) ==> X` transform
authorCameron McInally <cameron.mcinally@nyu.edu>
Fri, 17 May 2019 16:47:00 +0000 (16:47 +0000)
committerCameron McInally <cameron.mcinally@nyu.edu>
Fri, 17 May 2019 16:47:00 +0000 (16:47 +0000)
Differential Revision: https://reviews.llvm.org/D62013

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361047 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/fast-math.ll

index f1ec7b3..95ba69d 100644 (file)
@@ -4400,8 +4400,10 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
     return X;
 
   // fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored.
+  // fsub 0.0, (fneg X) ==> X if signed zeros are ignored.
   if (FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()) &&
-      match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))))
+      (match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))) ||
+       match(Op1, m_FNeg(m_Value(X)))))
     return X;
 
   // fsub nnan x, x ==> 0.0
index bb0e368..a53d6ff 100644 (file)
@@ -219,9 +219,7 @@ define float @fsub_0_0_x(float %a) {
 ; fsub nsz 0.0, (fneg X) ==> X
 define float @fneg_x(float %a) {
 ; CHECK-LABEL: @fneg_x(
-; CHECK-NEXT:    [[T1:%.*]] = fneg float [[A:%.*]]
-; CHECK-NEXT:    [[RET:%.*]] = fsub nsz float 0.000000e+00, [[T1]]
-; CHECK-NEXT:    ret float [[RET]]
+; CHECK-NEXT:    ret float [[A:%.*]]
 ;
   %t1 = fneg float %a
   %ret = fsub nsz float 0.0, %t1
@@ -239,9 +237,7 @@ define <2 x float> @fsub_0_0_x_vec_undef1(<2 x float> %a) {
 
 define <2 x float> @fneg_x_vec_undef1(<2 x float> %a) {
 ; CHECK-LABEL: @fneg_x_vec_undef1(
-; CHECK-NEXT:    [[T1:%.*]] = fneg <2 x float> [[A:%.*]]
-; CHECK-NEXT:    [[RET:%.*]] = fsub nsz <2 x float> <float 0.000000e+00, float undef>, [[T1]]
-; CHECK-NEXT:    ret <2 x float> [[RET]]
+; CHECK-NEXT:    ret <2 x float> [[A:%.*]]
 ;
   %t1 = fneg <2 x float> %a
   %ret = fsub nsz <2 x float> <float 0.0, float undef>, %t1