[llvm] [InstCombine] Remove m_OneUse requirement only for max, not min (PR #81505)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 09:10:46 PST 2024
================
@@ -2288,11 +2288,18 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// max X, -X --> fabs X
// min X, -X --> -(fabs X)
- // TODO: Remove one-use limitation? That is obviously better for max.
- // It would be an extra instruction for min (fnabs), but that is
- // still likely better for analysis and codegen.
- if ((match(Arg0, m_OneUse(m_FNeg(m_Value(X)))) && Arg1 == X) ||
- (match(Arg1, m_OneUse(m_FNeg(m_Value(X)))) && Arg0 == X)) {
+ // TODO: Remove one-use limitation? That is obviously better for max,
+ // hence why we don't check for one-use for that. However,
+ // it would be an extra instruction for min (fnabs), but
+ // that is still likely better for analysis and codegen.
+ auto IsMinMaxOrXNegX = [IID, &X](Value *Op0, Value *Op1) {
+ if (match(Op0, m_FNeg(m_Value(X))) && match(Op1, m_Specific(X)))
+ return Op0->hasOneUse() ||
+ (IID != Intrinsic::minimum && IID != Intrinsic::minnum);
+ return false;
+ };
+
+ if (IsMinMaxOrXNegX(Arg0, Arg1) || IsMinMaxOrXNegX(Arg1, Arg0)) {
----------------
goldsteinn wrote:
Doesn't seem to be the case: https://godbolt.org/z/d9Gqqdneb
either way, its generally not reliable enough to rely on a true canonicalization.
https://github.com/llvm/llvm-project/pull/81505
More information about the llvm-commits
mailing list