[all-commits] [llvm/llvm-project] 0a39c8: [InstCombine] Fold `select Cond, not X, X` into `C...

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Tue Jun 4 08:50:40 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0a39c88e81dadca9f6ceef8e0b0be0ed692fe4fe
      https://github.com/llvm/llvm-project/commit/0a39c88e81dadca9f6ceef8e0b0be0ed692fe4fe
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2024-06-04 (Tue, 04 Jun 2024)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/select-cmp.ll

  Log Message:
  -----------
  [InstCombine] Fold `select Cond, not X, X` into `Cond ^ X` (#93591)

See the following example:
```
define i1 @src(i64 %x, i1 %y) {
  %1526 = icmp ne i64 %x, 0
  %1527 = icmp eq i64 %x, 0
  %sel = select i1 %y, i1 %1526, i1 %1527
  ret i1 %sel
}

define i1 @tgt(i64 %x, i1 %y) {
  %1527 = icmp eq i64 %x, 0
  %sel = xor i1 %y, %1527
  ret i1 %sel
}
```
I find that this pattern is common in C/C++/Rust code base.
This patch folds `select Cond, Y, X` into `Cond ^ X` iff:
1. X has the same type as Cond
2. X is poison -> Y is poison
3. X == !Y

Alive2: https://alive2.llvm.org/ce/z/hSmkHS



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