[llvm] [InstCombine] Generalise optimisation of redundant floating point comparisons with `ConstantFPRange` (PR #159315)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 08:31:13 PDT 2025
================
@@ -1812,6 +1813,61 @@ static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
return nullptr;
}
+/// Test if a pair of compares with a shared operand and 2 constants has an
+/// empty set intersection, full set union, or if one compare is a superset of
+/// the other.
+static Value *simplifyAndOrOfFCmpsWithConstants(FCmpInst *Cmp0, FCmpInst *Cmp1,
+ bool IsAnd) {
+ // Look for this pattern: {and/or} (fcmp X, C0), (fcmp X, C1)).
+ if (Cmp0->getOperand(0) != Cmp1->getOperand(0))
+ return nullptr;
+
+ const APFloat *C0, *C1;
+ if (!match(Cmp0->getOperand(1), m_APFloat(C0)) ||
+ !match(Cmp1->getOperand(1), m_APFloat(C1)))
+ return nullptr;
+
+ auto Range0 = ConstantFPRange::makeExactFCmpRegion(Cmp0->getPredicate(), *C0);
+ auto Range1 = ConstantFPRange::makeExactFCmpRegion(Cmp1->getPredicate(), *C1);
----------------
dtcxzyw wrote:
```suggestion
auto Range0 = ConstantFPRange::makeExactFCmpRegion(IsAnd ? Cmp0->getPredicate() : Cmp0->getInversePredicate(), *C0);
auto Range1 = ConstantFPRange::makeExactFCmpRegion(IsAnd ? Cmp1->getPredicate() : Cmp1->getInversePredicate(), *C1);
```
https://github.com/llvm/llvm-project/pull/159315
More information about the llvm-commits
mailing list