[llvm] [DAGCombiner] Turn `(neg (max x, (neg x)))` into `(min x, (neg x))` (PR #120666)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 23 09:48:47 PST 2024
================
@@ -3949,6 +3949,40 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
if (SDValue Result = TLI.expandABS(N1.getNode(), DAG, true))
return Result;
+ // Similar to the previous rule, but this time targeting an expanded abs.
+ // (sub 0, (max X, (sub 0, X))) --> (min X, (sub 0, X))
+ // as well as
+ // (sub 0, (min X, (sub 0, X))) --> (max X, (sub 0, X))
+ // Note that these two are applicable to both signed and unsigned min/max.
+ SDValue X;
+ SDValue S0;
+ auto NegPat = m_AllOf(m_Neg(m_Deferred(X)), m_Value(S0));
+ if (LegalOperations &&
----------------
mshockwave wrote:
> I doubt in practice the legality of min is different than max
This, and even if max is illegal, I think it'll be expanded (while min is not), which makes this transformation even more profitable.
https://github.com/llvm/llvm-project/pull/120666
More information about the llvm-commits
mailing list