[llvm] [InstCombine] Fold expression using basic properties of floor and ceiling function (PR #107107)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 05:40:55 PDT 2024
================
@@ -8178,6 +8178,75 @@ static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
return nullptr;
}
+static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
+ InstCombinerImpl &IC) {
+ Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
+ Type *OpType = LHS->getType();
+ CmpInst::Predicate Pred = I.getPredicate();
+
+ bool FloorX = match(LHS, m_Intrinsic<Intrinsic::floor>(m_Specific(RHS)));
+ bool CeilX = match(LHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(RHS)));
+
+ if (!FloorX && !CeilX) {
+ if ((FloorX = match(RHS, m_Intrinsic<Intrinsic::floor>(m_Specific(LHS)))) ||
+ (CeilX = match(RHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(LHS))))) {
+ std::swap(LHS, RHS);
+ Pred = I.getSwappedPredicate();
+ }
+ }
----------------
c8ef wrote:
I believe we still need to include the `fcmp` instruction in the function to preserve the `fmf` flags. The current implementation should be sufficient.
https://github.com/llvm/llvm-project/pull/107107
More information about the llvm-commits
mailing list