[llvm] [InstCombine] Handle isNanOrInf idioms (PR #80414)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 07:02:53 PST 2024


================
@@ -1827,6 +1827,35 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
     }
   }
 
+  // (icmp eq (and (bitcast X to int), ExponentMask), ExponentMask) -->
+  // llvm.is.fpclass(X, fcInf|fcNan)
+  // (icmp ne (and (bitcast X to int), ExponentMask), ExponentMask) -->
+  // llvm.is.fpclass(X, ~(fcInf|fcNan))
+  Value *V;
+  if (!Cmp.getParent()->getParent()->hasFnAttribute(
+          Attribute::NoImplicitFloat) &&
+      Cmp.isEquality() && match(X, m_OneUse(m_BitCast(m_Value(V))))) {
+    Type *SrcType = V->getType();
+    Type *DstType = X->getType();
+    // Make sure the bitcast doesn't change between scalar and vector and
+    // doesn't change the number of vector elements.
+    if (SrcType->isVectorTy() == DstType->isVectorTy() &&
+        SrcType->getScalarSizeInBits() == DstType->getScalarSizeInBits()) {
+      Type *FPType = SrcType->getScalarType();
+      if (FPType->isIEEELikeFPTy() && C1 == *C2) {
----------------
arsenm wrote:

Can make this one big if ?Just hoist the FPType def? 

https://github.com/llvm/llvm-project/pull/80414


More information about the llvm-commits mailing list