[all-commits] [llvm/llvm-project] 0ab445: [InstCombine] Fold `cttz(lshr(-1, x) + 1)` to `wid...

Monad via All-commits all-commits at lists.llvm.org
Mon May 6 19:07:13 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0ab4458df0688955620b72cc2c72a32dffad3615
      https://github.com/llvm/llvm-project/commit/0ab4458df0688955620b72cc2c72a32dffad3615
  Author: Monad <yanwqmonad at gmail.com>
  Date:   2024-05-07 (Tue, 07 May 2024)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    M llvm/test/Transforms/InstCombine/cttz.ll

  Log Message:
  -----------
  [InstCombine] Fold `cttz(lshr(-1, x) + 1)` to `width - x` (#91244)

Fold
``` llvm
define i64 @src(i64 %50) {
  %52 = lshr i64 -1, %50
  %53 = add i64 %52, 1
  %54 = call i64 @llvm.cttz.i64(i64 %53, i1 false)
  ret i64 %54
}
```
to
``` llvm
define i64 @tgt(i64 %50) {
  %52 = sub i64 64, %50
  ret i64 %52
}
```

as
https://github.com/llvm/llvm-project/pull/91171#pullrequestreview-2040663002
pointed out.

Alive2 proof: https://alive2.llvm.org/ce/z/2aHfYa

Note: the `ctlz` version of this pattern seems not exist in dtcxzyw's
benchmark, so put it aside for now.



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