[llvm] [CodeGenPrepare] Reverse the canonicalization of isInf/isNanOrInf (PR #81572)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 05:03:41 PDT 2024
================
@@ -1943,6 +1943,36 @@ static bool swapICmpOperandsToExposeCSEOpportunities(CmpInst *Cmp) {
return false;
}
+static bool foldFCmpToFPClassTest(CmpInst *Cmp, const TargetLowering &TLI,
+ const DataLayout &DL) {
+ FCmpInst *FCmp = dyn_cast<FCmpInst>(Cmp);
+ if (!FCmp)
+ return false;
+
+ // Reverse the canonicalization if it is a FP class test
+ auto ShouldReverseTransform = [](FPClassTest ClassTest) {
+ return ClassTest == fcInf || ClassTest == (fcInf | fcNan);
+ };
+ auto [ClassVal, ClassTest] =
+ fcmpToClassTest(FCmp->getPredicate(), *FCmp->getParent()->getParent(),
+ FCmp->getOperand(0), FCmp->getOperand(1));
+ if (!ClassVal)
+ return false;
+
+ if (!ShouldReverseTransform(ClassTest) && !ShouldReverseTransform(~ClassTest))
+ return false;
+
+ // Don't fold if the target offers free fabs.
+ if (TLI.isFAbsFree(TLI.getValueType(DL, ClassVal->getType())))
----------------
dtcxzyw wrote:
Emm, TTI/TLI doesn't provide a hook for querying the legality of fcmp predicates :(
Could you please provide a test for demonstration?
https://github.com/llvm/llvm-project/pull/81572
More information about the llvm-commits
mailing list