[llvm] [InstCombine] Fold expression using basic properties of floor and ceiling function (PR #107107)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 19:28:40 PDT 2024
================
@@ -8178,6 +8178,81 @@ static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
return nullptr;
}
+static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
+ InstCombinerImpl &CI) {
+ Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
+ Type *OpType = LHS->getType();
+ CmpInst::Predicate Pred = I.getPredicate();
+
+ bool floor_x = match(LHS, m_Intrinsic<Intrinsic::floor>(m_Specific(RHS)));
+ bool x_floor = match(RHS, m_Intrinsic<Intrinsic::floor>(m_Specific(LHS)));
+ bool ceil_x = match(LHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(RHS)));
+ bool x_ceil = match(RHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(LHS)));
+
+ if (x_floor || x_ceil) {
+ std::swap(LHS, RHS);
+ Pred = I.getSwappedPredicate();
+ (x_floor ? floor_x : ceil_x) = true;
----------------
c8ef wrote:
Done. Code style issues have also been addressed.
https://github.com/llvm/llvm-project/pull/107107
More information about the llvm-commits
mailing list