[llvm] r327339 - [PatternMatch] enhance m_NaN() to ignore undef elements in vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 15:18:47 PDT 2018


Author: spatel
Date: Mon Mar 12 15:18:47 2018
New Revision: 327339

URL: http://llvm.org/viewvc/llvm-project?rev=327339&view=rev
Log:
[PatternMatch] enhance m_NaN() to ignore undef elements in vectors

Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=327339&r1=327338&r2=327339&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Mon Mar 12 15:18:47 2018
@@ -157,17 +157,6 @@ struct match_any_zero {
 /// floating point constants, this will match negative zero and positive zero
 inline match_any_zero m_AnyZero() { return match_any_zero(); }
 
-struct match_nan {
-  template <typename ITy> bool match(ITy *V) {
-    if (const auto *C = dyn_cast<Constant>(V))
-      return C->isNaN();
-    return false;
-  }
-};
-
-/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
-inline match_nan m_NaN() { return match_nan(); }
-
 struct apint_match {
   const APInt *&Res;
 
@@ -422,6 +411,14 @@ inline cstfp_pred_ty<is_neg_zero> m_NegZ
   return cstfp_pred_ty<is_neg_zero>();
 }
 
+struct is_nan {
+  bool isValue(const APFloat &C) { return C.isNaN(); }
+};
+// Match an arbitrary NaN constant. This includes quiet and signalling nans.
+inline cstfp_pred_ty<is_nan> m_NaN() {
+  return cstfp_pred_ty<is_nan>();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 template <typename Class> struct bind_ty {

Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll?rev=327339&r1=327338&r2=327339&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll Mon Mar 12 15:18:47 2018
@@ -356,8 +356,7 @@ define <2 x i1> @orderedCompareWithNaNVe
 
 define <2 x i1> @orderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
 ; CHECK-LABEL: @orderedCompareWithNaNVector_undef_elt(
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt <2 x double> [[A:%.*]], <double 0xFFFFFFFFFFFFFFFF, double undef>
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double undef>
   ret <2 x i1> %cmp
@@ -365,8 +364,7 @@ define <2 x i1> @orderedCompareWithNaNVe
 
 define <2 x i1> @unorderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
 ; CHECK-LABEL: @unorderedCompareWithNaNVector_undef_elt(
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp ult <2 x double> [[A:%.*]], <double undef, double 0xFFFFFFFFFFFFFFFF>
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %cmp = fcmp ult <2 x double> %A, <double undef, double 0xFFFFFFFFFFFFFFFF>
   ret <2 x i1> %cmp




More information about the llvm-commits mailing list