[llvm] ValueTracking: Identify implied fp classes by general fcmp (PR #66505)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 05:22:26 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;
+
+ assert(IsNegativeRHS == ConstRHS->isNegative());
+ assert(IsPositiveRHS == !ConstRHS->isNegative());
+
+ Value *Src = LHS;
+ const bool IsFabs = LookThroughSrc && match(LHS, m_FAbs(m_Value(Src)));
+
+ if (IsFabs)
+ RHSClass = llvm::inverse_fabs(RHSClass);
+
+ if (Pred == FCmpInst::FCMP_OEQ)
+ return {Src, RHSClass, fcAllFlags};
+
+ if (Pred == FCmpInst::FCMP_UEQ) {
+ FPClassTest Class = RHSClass | fcNan;
+ return {Src, Class, ~fcNan};
+ }
+
+ if (Pred == FCmpInst::FCMP_ONE)
+ return {Src, ~fcNan, RHSClass};
----------------
arsenm wrote:
No? une implies may be nan, not may not be nan
https://github.com/llvm/llvm-project/pull/66505
More information about the llvm-commits
mailing list