[PATCH] D52934: [FPEnv] PatternMatcher support for checking FNEG ignoring signed zeros

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 5 08:11:05 PDT 2018


cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, craig.topper, andrew.w.kaylor, uweigand, kpn, jyknight.
Herald added a subscriber: llvm-commits.

@spatel

This is the first patch in a series to replace BinaryOperator::isFNeg(...) with more general pattern matcher calls.

We'll need a mechanism in the pattern matcher to match FNeg patterns that ignore signed zeros. I propose adding a new pattern matcher function, called m_ISZFNeg(...). This patch is one possible solution, but I'll leave it open for discussion. I'll also add that I have not worked on the pattern matcher before, so please review thoroughly.

There are a handful of tests that exercise the modified xform in test/Transforms/InstSimplify/fast-math.ll. So, I did not add new tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D52934

Files:
  include/llvm/IR/PatternMatch.h
  lib/Analysis/InstructionSimplify.cpp


Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -4508,10 +4508,8 @@
     // -X /  X -> -1.0 and
     //  X / -X -> -1.0 are legal when NaNs are ignored.
     // We can ignore signed zeros because +-0.0/+-0.0 is NaN and ignored.
-    if ((BinaryOperator::isFNeg(Op0, /*IgnoreZeroSign=*/true) &&
-         BinaryOperator::getFNegArgument(Op0) == Op1) ||
-        (BinaryOperator::isFNeg(Op1, /*IgnoreZeroSign=*/true) &&
-         BinaryOperator::getFNegArgument(Op1) == Op0))
+    if ((match(Op0, m_ISZFNeg((m_Value(X)))) && X == Op1) ||
+        (match(Op1, m_ISZFNeg((m_Value(X)))) && X == Op0))
       return ConstantFP::get(Op0->getType(), -1.0);
   }
 
Index: include/llvm/IR/PatternMatch.h
===================================================================
--- include/llvm/IR/PatternMatch.h
+++ include/llvm/IR/PatternMatch.h
@@ -666,6 +666,13 @@
   return m_FSub(m_NegZeroFP(), X);
 }
 
+/// Match 'fneg X' as 'fsub +-0.0, X'.
+template <typename RHS>
+inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
+m_ISZFNeg(const RHS &X) {
+  return m_FSub(m_AnyZeroFP(), X);
+}
+
 template <typename LHS, typename RHS>
 inline BinaryOp_match<LHS, RHS, Instruction::Mul> m_Mul(const LHS &L,
                                                         const RHS &R) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52934.168474.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181005/5907e636/attachment.bin>


More information about the llvm-commits mailing list