[llvm] r344084 - [FPEnv] PatternMatcher support for checking FNEG ignoring signed zeros

Cameron McInally via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 9 14:48:00 PDT 2018


Author: mcinally
Date: Tue Oct  9 14:48:00 2018
New Revision: 344084

URL: http://llvm.org/viewvc/llvm-project?rev=344084&view=rev
Log:
[FPEnv] PatternMatcher support for checking FNEG ignoring signed zeros

https://reviews.llvm.org/D52934


Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/fast-math.ll

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=344084&r1=344083&r2=344084&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Tue Oct  9 14:48:00 2018
@@ -666,6 +666,13 @@ m_FNeg(const RHS &X) {
   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_FNegNSZ(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) {

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=344084&r1=344083&r2=344084&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Oct  9 14:48:00 2018
@@ -4508,10 +4508,8 @@ static Value *SimplifyFDivInst(Value *Op
     // -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_FNegNSZ(m_Specific(Op1))) ||
+        match(Op1, m_FNegNSZ(m_Specific(Op0))))
       return ConstantFP::get(Op0->getType(), -1.0);
   }
 

Modified: llvm/trunk/test/Transforms/InstSimplify/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/fast-math.ll?rev=344084&r1=344083&r2=344084&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/fast-math.ll Tue Oct  9 14:48:00 2018
@@ -401,9 +401,7 @@ define float @fdiv_neg_swapped2(float %f
 
 define <2 x float> @fdiv_neg_vec_undef_elt(<2 x float> %f) {
 ; CHECK-LABEL: @fdiv_neg_vec_undef_elt(
-; CHECK-NEXT:    [[NEG:%.*]] = fsub <2 x float> <float 0.000000e+00, float undef>, [[F:%.*]]
-; CHECK-NEXT:    [[DIV:%.*]] = fdiv nnan <2 x float> [[F]], [[NEG]]
-; CHECK-NEXT:    ret <2 x float> [[DIV]]
+; CHECK-NEXT:    ret <2 x float> <float -1.000000e+00, float -1.000000e+00>
 ;
   %neg = fsub <2 x float> <float 0.0, float undef>, %f
   %div = fdiv nnan <2 x float> %f, %neg




More information about the llvm-commits mailing list