[llvm] [InstCombine] Fold isnan idioms (PR #101510)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 09:24:20 PDT 2024
================
@@ -363,8 +363,28 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(
// deduce anything from it.
// For example,
// (icmp ne (A & 12), 0) & (icmp eq (A & 3), 1) -> no folding.
- if ((*BCst & *DCst) == 0)
+ if ((*BCst & *DCst) == 0) {
+ // Try to fold isNaN idiom:
+ // (icmp ne (A & FractionBits), 0) & (icmp eq (A & ExpBits), ExpBits) ->
+ // isNaN(A)
+ Value *Src;
+ if (match(A, m_ElementWiseBitCast(m_Value(Src))) &&
+ Src->getType()->getScalarType()->isIEEELikeFPTy() &&
+ !Builder.GetInsertBlock()->getParent()->hasFnAttribute(
+ Attribute::NoImplicitFloat)) {
+ APInt ExpBits =
+ APFloat::getInf(Src->getType()->getScalarType()->getFltSemantics())
+ .bitcastToAPInt();
----------------
arsenm wrote:
Early exit on the ExpBits tests here?
https://github.com/llvm/llvm-project/pull/101510
More information about the llvm-commits
mailing list