[PATCH] D62013: [InstSimplify] Add unary fneg to `fsub 0.0, (fneg X) ==> X` transform

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 09:23:21 PDT 2019


cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, arsenm, kpn, craig.topper, andrew.w.kaylor.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.

Also, fix a test mistake I made when adding this new test. That was r360808.

Note that we could probably do a little better with the pattern matching here, but functionality first...


Repository:
  rL LLVM

https://reviews.llvm.org/D62013

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


Index: llvm/test/Transforms/InstSimplify/fast-math.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/fast-math.ll
+++ llvm/test/Transforms/InstSimplify/fast-math.ll
@@ -219,12 +219,10 @@
 ; fsub nsz 0.0, (fneg X) ==> X
 define float @fneg_x(float %a) {
 ; CHECK-LABEL: @fneg_x(
-; CHECK-NEXT:    [[T1:%.*]] = fsub float 0.000000e+00, [[A:%.*]]
-; CHECK-NEXT:    [[RET:%.*]] = fneg nsz float [[T1]]
-; CHECK-NEXT:    ret float [[RET]]
+; CHECK-NEXT:    ret float [[A:%.*]]
 ;
-  %t1 = fsub float 0.0, %a
-  %ret = fneg nsz float %t1
+  %t1 = fneg float %a
+  %ret = fsub nsz float 0.0, %t1
   ret float %ret
 }
 
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4369,9 +4369,10 @@
       match(Op1, m_FSub(m_NegZeroFP(), m_Value(X))))
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62013.199845.patch
Type: text/x-patch
Size: 1356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/dc68c17a/attachment.bin>


More information about the llvm-commits mailing list