[all-commits] [llvm/llvm-project] 2291d0: [DAGCombiner] Turn `(neg (max x, (neg x)))` into `...

Min-Yih Hsu via All-commits all-commits at lists.llvm.org
Thu Jan 2 16:29:17 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2291d0aba927b885cf39150e59fde466a2524bb5
      https://github.com/llvm/llvm-project/commit/2291d0aba927b885cf39150e59fde466a2524bb5
  Author: Min-Yih Hsu <min.hsu at sifive.com>
  Date:   2025-01-02 (Thu, 02 Jan 2025)

  Changed paths:
    M llvm/include/llvm/CodeGen/ISDOpcodes.h
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    M llvm/test/CodeGen/RISCV/neg-abs.ll
    A llvm/test/CodeGen/RISCV/rvv/fixed-neg-abs.ll

  Log Message:
  -----------
  [DAGCombiner] Turn `(neg (max x, (neg x)))` into `(min x, (neg x))` (#120666)

This pattern was originally spotted in 429.mcf by @topperc.

We already have a DAGCombiner pattern to turn `(neg (abs x))` into `(min
x, (neg x))`. But in some cases `(neg (max x, (neg x)))` is formed by an
expanded `abs` followed by a `neg` that is generated only after the
`abs` expansion. This patch adds a separate pattern to match cases like
this, as well as its inverse pattern: `(neg (min X, (neg X))) --> (max
X, (neg X))`.

This pattern is applicable to both signed and unsigned min/max.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list