[all-commits] [llvm/llvm-project] 4fdf07: [AArch64] Use CNEG for absolute difference pattern...

Ricardo Jesus via All-commits all-commits at lists.llvm.org
Wed Jul 30 04:29:35 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4fdf07fd46f250804bc1ce5f9193a3ed990e308b
      https://github.com/llvm/llvm-project/commit/4fdf07fd46f250804bc1ce5f9193a3ed990e308b
  Author: Ricardo Jesus <rjj at nvidia.com>
  Date:   2025-07-30 (Wed, 30 Jul 2025)

  Changed paths:
    M llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
    M llvm/test/CodeGen/AArch64/abds-neg.ll
    M llvm/test/CodeGen/AArch64/abds.ll
    M llvm/test/CodeGen/AArch64/abdu-neg.ll
    M llvm/test/CodeGen/AArch64/abdu.ll
    M llvm/test/CodeGen/AArch64/midpoint-int.ll

  Log Message:
  -----------
  [AArch64] Use CNEG for absolute difference patterns. (#151177)

The current code generated for absolute difference patterns
(a > b ? a - b : b - a) typically consists of sequences of:
```
  sub w8, w1, w0
  subs w9, w0, w1
  csel w0, w9, w8, hi
```

The first sub is redundant if the csel is replaced by a cneg:
```
  subs w8, w0, w1
  cneg w0, w8, ls
```

This is achieved by canonicalising
```
  select_cc lhs, rhs, sub(lhs, rhs), sub(rhs, lhs), cc ->
  select_cc lhs, rhs, sub(lhs, rhs), neg(sub(lhs, rhs)), cc
  
  select_cc lhs, rhs, sub(rhs, lhs), sub(lhs, rhs), cc ->
  select_cc lhs, rhs, neg(sub(lhs, rhs)), sub(lhs, rhs), cc
```
as the second forms can already be matched.

This helps with some of the patterns in #118413.



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