[llvm] Optimize fptrunc(x)>=C1 --> x>=C2 (PR #99475)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 20 16:08:41 PDT 2024
================
@@ -7882,6 +7892,93 @@ static Instruction *foldFCmpReciprocalAndZero(FCmpInst &I, Instruction *LHSI,
return new FCmpInst(Pred, LHSI->getOperand(1), RHSC, "", &I);
}
+// Fold fptrunc(x) < constant --> x < constant if possible.
+static Instruction *foldFCmpFpTrunc(FCmpInst &I, Instruction *LHSI,
+ Constant *RHSC) {
+ FCmpInst::Predicate Pred = I.getPredicate();
+ bool RoundDown = false;
+
+ if (Pred == FCmpInst::FCMP_OGE || Pred == FCmpInst::FCMP_UGE ||
+ Pred == FCmpInst::FCMP_OLT || Pred == FCmpInst::FCMP_ULT)
+ RoundDown = true;
+ else if (Pred == FCmpInst::FCMP_OGT || Pred == FCmpInst::FCMP_UGT ||
+ Pred == FCmpInst::FCMP_OLE || Pred == FCmpInst::FCMP_ULE)
+ RoundDown = false;
+ else
----------------
arsenm wrote:
uge, ule cases not tested. Plus negative test for others
https://github.com/llvm/llvm-project/pull/99475
More information about the llvm-commits
mailing list