[llvm] [InstCombine] fold `cond ? x : -x == 0` into `x == 0` (PR #85673)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 09:10:22 PDT 2024
================
@@ -7972,6 +7972,13 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
Constant *RHSC;
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
switch (LHSI->getOpcode()) {
+ case Instruction::Select:
+ if (FCmpInst::isEquality(Pred) && match(RHSC, m_AnyZeroFP()) &&
+ (match(LHSI,
+ m_Select(m_Value(), m_Value(X), m_FNeg(m_Deferred(X)))) ||
+ match(LHSI, m_Select(m_Value(), m_FNeg(m_Value(X)), m_Deferred(X)))))
+ return new FCmpInst(Pred, X, RHSC, "", &I);
----------------
jayfoad wrote:
This will drop FMF and the name of the original fcmp inst. How about:
```suggestion
return replaceOperand(I, 0, X);
```
https://github.com/llvm/llvm-project/pull/85673
More information about the llvm-commits
mailing list