[all-commits] [llvm/llvm-project] 26ccc6: [InstCombine] Drop nuw flag when CtlzOp is a sub n...

Tom Stellard via All-commits all-commits at lists.llvm.org
Thu May 16 11:43:50 PDT 2024


  Branch: refs/heads/release/18.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 26ccc6b5c1c73a92e5d08299065709e1d163b6c2
      https://github.com/llvm/llvm-project/commit/26ccc6b5c1c73a92e5d08299065709e1d163b6c2
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2024-05-16 (Thu, 16 May 2024)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/bit_ceil.ll

  Log Message:
  -----------
  [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776)

See the following case:
```
define i32 @src1(i32 %x) {
  %dec = sub nuw i32 -2, %x
  %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
  %sub = sub nsw i32 32, %ctlz
  %shl = shl i32 1, %sub
  %ugt = icmp ult i32 %x, -2
  %sel = select i1 %ugt, i32 %shl, i32 1
  ret i32 %sel
}

define i32 @tgt1(i32 %x) {
  %dec = sub nuw i32 -2, %x
  %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
  %sub = sub nsw i32 32, %ctlz
  %and = and i32 %sub, 31
  %shl = shl nuw i32 1, %and
  ret i32 %shl
}
```
`nuw` in `%dec` should be dropped after the select instruction is
eliminated.

Alive2: https://alive2.llvm.org/ce/z/7S9529

Fixes https://github.com/llvm/llvm-project/issues/91691.

(cherry picked from commit b5f4210e9f51f938ae517f219f04f9ab431a2684)


  Commit: 2a4a0bf1db8b828f104123de52d9f9cace020ed0
      https://github.com/llvm/llvm-project/commit/2a4a0bf1db8b828f104123de52d9f9cace020ed0
  Author: Tom Stellard <tstellar at redhat.com>
  Date:   2024-05-16 (Thu, 16 May 2024)

  Changed paths:
    M llvm/test/Transforms/InstCombine/bit_ceil.ll

  Log Message:
  -----------
  Update llvm/test/Transforms/InstCombine/bit_ceil.ll

Co-authored-by: Yingwei Zheng <dtcxzyw at qq.com>


Compare: https://github.com/llvm/llvm-project/compare/aa2549e2bf12...2a4a0bf1db8b

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