[llvm] ValueTracking: Identify implied fp classes by general fcmp (PR #66505)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 00:58:01 PST 2024


================
@@ -4245,6 +4245,139 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
   return {Src, Mask};
 }
 
+std::tuple<Value *, FPClassTest, FPClassTest>
+llvm::fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
+                       const APFloat *ConstRHS, bool LookThroughSrc) {
+  auto [Val, ClassMask] =
+      fcmpToClassTest(Pred, F, LHS, ConstRHS, LookThroughSrc);
+  if (Val)
+    return {Val, ClassMask, ~ClassMask};
+
+  FPClassTest RHSClass = ConstRHS->classify();
+  assert((RHSClass == fcPosNormal || RHSClass == fcNegNormal ||
+          RHSClass == fcPosSubnormal || RHSClass == fcNegSubnormal) &&
+         "should have been recognized as an exact class test");
+
+  const bool IsNegativeRHS = (RHSClass & fcNegative) == RHSClass;
+  const bool IsPositiveRHS = (RHSClass & fcPositive) == RHSClass;
----------------
jayfoad wrote:

Then the asserts immediately below must be broken since they effectively assert that `IsNegativeRHS == !IsPositiveRHS`.

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


More information about the llvm-commits mailing list