[all-commits] [llvm/llvm-project] 807cc3: [DAGCombiner] Fold subtraction if above threshold ...

Piotr Fusik via All-commits all-commits at lists.llvm.org
Thu Apr 10 00:08:30 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 807cc3791fabd47bd24d57a8e4ab7df9117b3ede
      https://github.com/llvm/llvm-project/commit/807cc3791fabd47bd24d57a8e4ab7df9117b3ede
  Author: Piotr Fusik <p.fusik at samsung.com>
  Date:   2025-04-10 (Thu, 10 Apr 2025)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/test/CodeGen/RISCV/rv32zbb.ll
    M llvm/test/CodeGen/RISCV/rv64zbb.ll

  Log Message:
  -----------
  [DAGCombiner] Fold subtraction if above threshold to `umin` (#134235)

Folds patterns such as:

    unsigned foo(unsigned x, unsigned y) {
      return x >= y ? x - y : x;
    }

Before, on RISC-V:

    sltu    a2, a0, a1
    addi    a2, a2, -1
    and     a1, a1, a2
    subw    a0, a0, a1

Or, with Zicond:

    sltu    a2, a0, a1
    czero.nez a1, a1, a2
    subw    a0, a0, a1

After, with Zbb:

    subw    a1, a0, a1
    minu    a0, a0, a1

Only applies to unsigned comparisons.
If `x >= y` then `x - y` is less than or equal `x`.
Otherwise, `x - y` wraps and is greater than `x`.



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