[llvm] [InstCombine] Implement `fcmp (fadd x, 0.0), y` => `fcmp x, y` optimization (PR #88476)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 12 00:20:44 PDT 2024
================
@@ -8100,6 +8100,13 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
return new FCmpInst(I.getSwappedPredicate(), X, NegC, "", &I);
}
+ // fcmp (fadd X, 0.0), Y --> fcmp X, Y
+ if (match(Op0, m_FAdd(m_Value(X), m_APFloat(C))) && C->isZero()) {
+ if (match(Op1, m_Value(Y))) {
+ return new FCmpInst(Pred, X, Y, "", &I);
+ }
+ }
----------------
dtcxzyw wrote:
```suggestion
if (match(Op0, m_FAdd(m_Value(X), m_AnyZeroFP())))
return new FCmpInst(Pred, X, Op1, "", &I);
if (match(Op1, m_FAdd(m_Value(X), m_AnyZeroFP())))
return new FCmpInst(Pred, Op0, X, "", &I);
```
1. Add a test for `fcmp X, (fadd Y, 0.0)`
2. Add a vector test for `fcmp (fadd X, <0.0, -0.0>), Y`
3. Add a test for fast-math flag preservation
https://github.com/llvm/llvm-project/pull/88476
More information about the llvm-commits
mailing list