[llvm] r329303 - [PatternMatch] define m_FNeg using m_FSub

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 08:36:55 PDT 2018


Author: spatel
Date: Thu Apr  5 08:36:55 2018
New Revision: 329303

URL: http://llvm.org/viewvc/llvm-project?rev=329303&view=rev
Log:
[PatternMatch] define m_FNeg using m_FSub

Using cstfp_pred_ty in the definition allows us to match vectors with undef elements.

This replicates the change for m_Not from D44076 / rL326823 and continues
towards making all pattern matchers allow undef elements in vectors.

Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/test/Transforms/InstCombine/fcmp.ll
    llvm/trunk/test/Transforms/InstCombine/fdiv.ll
    llvm/trunk/test/Transforms/InstCombine/fma.ll
    llvm/trunk/test/Transforms/InstCombine/fmul.ll

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=329303&r1=329302&r2=329303&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Thu Apr  5 08:36:55 2018
@@ -621,6 +621,13 @@ inline BinaryOp_match<LHS, RHS, Instruct
   return BinaryOp_match<LHS, RHS, Instruction::FSub>(L, R);
 }
 
+/// Match 'fneg X' as 'fsub -0.0, X'.
+template <typename RHS>
+inline BinaryOp_match<cstfp_pred_ty<is_neg_zero_fp>, RHS, Instruction::FSub>
+m_FNeg(const RHS &X) {
+  return m_FSub(m_NegZeroFP(), X);
+}
+
 template <typename LHS, typename RHS>
 inline BinaryOp_match<LHS, RHS, Instruction::Mul> m_Mul(const LHS &L,
                                                         const RHS &R) {
@@ -1181,31 +1188,6 @@ private:
 /// Match an integer negate.
 template <typename LHS> inline neg_match<LHS> m_Neg(const LHS &L) { return L; }
 
-template <typename LHS_t> struct fneg_match {
-  LHS_t L;
-
-  fneg_match(const LHS_t &LHS) : L(LHS) {}
-
-  template <typename OpTy> bool match(OpTy *V) {
-    if (auto *O = dyn_cast<Operator>(V))
-      if (O->getOpcode() == Instruction::FSub)
-        return matchIfFNeg(O->getOperand(0), O->getOperand(1));
-    return false;
-  }
-
-private:
-  bool matchIfFNeg(Value *LHS, Value *RHS) {
-    if (const auto *C = dyn_cast<Constant>(LHS))
-      return C->isNegativeZeroValue() && L.match(RHS);
-    return false;
-  }
-};
-
-/// Match a floating point negate.
-template <typename LHS> inline fneg_match<LHS> m_FNeg(const LHS &L) {
-  return L;
-}
-
 //===----------------------------------------------------------------------===//
 // Matchers for control flow.
 //

Modified: llvm/trunk/test/Transforms/InstCombine/fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fcmp.ll?rev=329303&r1=329302&r2=329303&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fcmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fcmp.ll Thu Apr  5 08:36:55 2018
@@ -68,8 +68,7 @@ define <2 x i1> @fneg_constant_swap_pred
 
 define <2 x i1> @fneg_constant_swap_pred_vec_undef(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_constant_swap_pred_vec_undef(
-; CHECK-NEXT:    [[NEG:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[X:%.*]]
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt <2 x float> [[NEG]], <float 1.000000e+00, float 2.000000e+00>
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt <2 x float> [[X:%.*]], <float -1.000000e+00, float -2.000000e+00>
 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
 ;
   %neg = fsub <2 x float> <float undef, float -0.0>, %x
@@ -101,9 +100,7 @@ define <2 x i1> @fneg_fneg_swap_pred_vec
 
 define <2 x i1> @fneg_fneg_swap_pred_vec_undef(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @fneg_fneg_swap_pred_vec_undef(
-; CHECK-NEXT:    [[NEG1:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[X:%.*]]
-; CHECK-NEXT:    [[NEG2:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[Y:%.*]]
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt <2 x float> [[NEG1]], [[NEG2]]
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt <2 x float> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
 ;
   %neg1 = fsub <2 x float> <float -0.0, float undef>, %x

Modified: llvm/trunk/test/Transforms/InstCombine/fdiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fdiv.ll?rev=329303&r1=329302&r2=329303&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fdiv.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fdiv.ll Thu Apr  5 08:36:55 2018
@@ -224,9 +224,7 @@ define <2 x float> @fneg_fneg_vec(<2 x f
 
 define <2 x float> @fneg_fneg_vec_undef_elts(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @fneg_fneg_vec_undef_elts(
-; CHECK-NEXT:    [[XNEG:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[X:%.*]]
-; CHECK-NEXT:    [[YNEG:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[Y:%.*]]
-; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[XNEG]], [[YNEG]]
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret <2 x float> [[DIV]]
 ;
   %xneg = fsub <2 x float> <float undef, float -0.0>, %x
@@ -267,8 +265,7 @@ define <2 x float> @fneg_dividend_consta
 
 define <2 x float> @fneg_dividend_constant_divisor_vec_undef_elt(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_dividend_constant_divisor_vec_undef_elt(
-; CHECK-NEXT:    [[NEG:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[X:%.*]]
-; CHECK-NEXT:    [[DIV:%.*]] = fdiv ninf <2 x float> [[NEG]], <float 3.000000e+00, float -8.000000e+00>
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv ninf <2 x float> [[X:%.*]], <float -3.000000e+00, float 8.000000e+00>
 ; CHECK-NEXT:    ret <2 x float> [[DIV]]
 ;
   %neg = fsub <2 x float> <float undef, float -0.0>, %x

Modified: llvm/trunk/test/Transforms/InstCombine/fma.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fma.ll?rev=329303&r1=329302&r2=329303&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fma.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fma.ll Thu Apr  5 08:36:55 2018
@@ -32,9 +32,7 @@ define <2 x float> @fma_fneg_x_fneg_y_ve
 
 define <2 x float> @fma_fneg_x_fneg_y_vec_undef(<2 x float> %x, <2 x float> %y, <2 x float> %z) {
 ; CHECK-LABEL: @fma_fneg_x_fneg_y_vec_undef(
-; CHECK-NEXT:    [[XN:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[X:%.*]]
-; CHECK-NEXT:    [[YN:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[Y:%.*]]
-; CHECK-NEXT:    [[FMA:%.*]] = call <2 x float> @llvm.fma.v2f32(<2 x float> [[XN]], <2 x float> [[YN]], <2 x float> [[Z:%.*]])
+; CHECK-NEXT:    [[FMA:%.*]] = call <2 x float> @llvm.fma.v2f32(<2 x float> [[X:%.*]], <2 x float> [[Y:%.*]], <2 x float> [[Z:%.*]])
 ; CHECK-NEXT:    ret <2 x float> [[FMA]]
 ;
   %xn = fsub <2 x float> <float -0.0, float undef>, %x

Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=329303&r1=329302&r2=329303&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Thu Apr  5 08:36:55 2018
@@ -24,8 +24,7 @@ define <2 x float> @neg_constant_vec(<2
 
 define <2 x float> @neg_constant_vec_undef(<2 x float> %x) {
 ; CHECK-LABEL: @neg_constant_vec_undef(
-; CHECK-NEXT:    [[SUB:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[X:%.*]]
-; CHECK-NEXT:    [[MUL:%.*]] = fmul ninf <2 x float> [[SUB]], <float 2.000000e+00, float 3.000000e+00>
+; CHECK-NEXT:    [[MUL:%.*]] = fmul ninf <2 x float> [[X:%.*]], <float -2.000000e+00, float -3.000000e+00>
 ; CHECK-NEXT:    ret <2 x float> [[MUL]]
 ;
   %sub = fsub <2 x float> <float undef, float -0.0>, %x
@@ -69,9 +68,7 @@ define <2 x float> @neg_neg_vec(<2 x flo
 
 define <2 x float> @neg_neg_vec_undef(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @neg_neg_vec_undef(
-; CHECK-NEXT:    [[SUB1:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[X:%.*]]
-; CHECK-NEXT:    [[SUB2:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[Y:%.*]]
-; CHECK-NEXT:    [[MUL:%.*]] = fmul arcp <2 x float> [[SUB1]], [[SUB2]]
+; CHECK-NEXT:    [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret <2 x float> [[MUL]]
 ;
   %sub1 = fsub <2 x float> <float -0.0, float undef>, %x
@@ -136,8 +133,8 @@ define <2 x float> @neg_sink_vec(<2 x fl
 
 define <2 x float> @neg_sink_vec_undef(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @neg_sink_vec_undef(
-; CHECK-NEXT:    [[SUB:%.*]] = fsub <2 x float> <float undef, float -0.000000e+00>, [[X:%.*]]
-; CHECK-NEXT:    [[MUL:%.*]] = fmul <2 x float> [[SUB]], [[Y:%.*]]
+; CHECK-NEXT:    [[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[MUL:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
 ; CHECK-NEXT:    ret <2 x float> [[MUL]]
 ;
   %sub = fsub <2 x float> <float undef, float -0.0>, %x




More information about the llvm-commits mailing list