[llvm] Optimize fptrunc(x)>=C1 --> x>=C2 (PR #99475)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 05:18:45 PDT 2024
================
@@ -7882,6 +7885,30 @@ static Instruction *foldFCmpReciprocalAndZero(FCmpInst &I, Instruction *LHSI,
return new FCmpInst(Pred, LHSI->getOperand(1), RHSC, "", &I);
}
+// Fold trunc(x) < constant --> x < constant if possible.
+static Instruction *foldFCmpFpTrunc(FCmpInst &I, Instruction *LHSI,
+ Constant *RHSC) {
+ //
+ FCmpInst::Predicate Pred = I.getPredicate();
+
+ // Check that predicates are valid.
+ if ((Pred != FCmpInst::FCMP_OGT) && (Pred != FCmpInst::FCMP_OLT) &&
+ (Pred != FCmpInst::FCMP_OGE) && (Pred != FCmpInst::FCMP_OLE))
+ return nullptr;
+
+ auto *LType = LHSI->getOperand(0)->getType();
+ auto *RType = RHSC->getType();
+
+ if (!(LType->isFloatingPointTy() && RType->isFloatingPointTy() &&
+ LType->getTypeID() >= RType->getTypeID()))
+ return nullptr;
+
+ auto *ROperand = llvm::ConstantFP::get(
+ LType, dyn_cast<ConstantFP>(RHSC)->getValue().convertToDouble());
----------------
arsenm wrote:
Don't use convertToDouble, keep this entirely in APFloat
https://github.com/llvm/llvm-project/pull/99475
More information about the llvm-commits
mailing list