Skip to content

Commit 1dbb6b7

Browse files
committedMar 12, 2018
[PatternMatch] enhance m_NaN() to ignore undef elements in vectors
llvm-svn: 327339
1 parent 79a7c4f commit 1dbb6b7

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed
 

Diff for: ‎llvm/include/llvm/IR/PatternMatch.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,6 @@ struct match_any_zero {
157157
/// floating point constants, this will match negative zero and positive zero
158158
inline match_any_zero m_AnyZero() { return match_any_zero(); }
159159

160-
struct match_nan {
161-
template <typename ITy> bool match(ITy *V) {
162-
if (const auto *C = dyn_cast<Constant>(V))
163-
return C->isNaN();
164-
return false;
165-
}
166-
};
167-
168-
/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
169-
inline match_nan m_NaN() { return match_nan(); }
170-
171160
struct apint_match {
172161
const APInt *&Res;
173162

@@ -422,6 +411,14 @@ inline cstfp_pred_ty<is_neg_zero> m_NegZero() {
422411
return cstfp_pred_ty<is_neg_zero>();
423412
}
424413

414+
struct is_nan {
415+
bool isValue(const APFloat &C) { return C.isNaN(); }
416+
};
417+
// Match an arbitrary NaN constant. This includes quiet and signalling nans.
418+
inline cstfp_pred_ty<is_nan> m_NaN() {
419+
return cstfp_pred_ty<is_nan>();
420+
}
421+
425422
///////////////////////////////////////////////////////////////////////////////
426423

427424
template <typename Class> struct bind_ty {

Diff for: ‎llvm/test/Transforms/InstSimplify/floating-point-compare.ll

+2-4
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,15 @@ define <2 x i1> @orderedCompareWithNaNVector(<2 x double> %A) {
356356

357357
define <2 x i1> @orderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
358358
; CHECK-LABEL: @orderedCompareWithNaNVector_undef_elt(
359-
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <2 x double> [[A:%.*]], <double 0xFFFFFFFFFFFFFFFF, double undef>
360-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
359+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
361360
;
362361
%cmp = fcmp olt <2 x double> %A, <double 0xFFFFFFFFFFFFFFFF, double undef>
363362
ret <2 x i1> %cmp
364363
}
365364

366365
define <2 x i1> @unorderedCompareWithNaNVector_undef_elt(<2 x double> %A) {
367366
; CHECK-LABEL: @unorderedCompareWithNaNVector_undef_elt(
368-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <2 x double> [[A:%.*]], <double undef, double 0xFFFFFFFFFFFFFFFF>
369-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
367+
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
370368
;
371369
%cmp = fcmp ult <2 x double> %A, <double undef, double 0xFFFFFFFFFFFFFFFF>
372370
ret <2 x i1> %cmp

0 commit comments

Comments
 (0)
Please sign in to comment.