[llvm] [InstCombine] Fix Issue 65107 (PR #78444)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 03:09:48 PST 2024


nikic wrote:

@ParkHanbum My suggestion is to fold
```llvm
define i1 @f(i16 %0) {
  br label %BB1

BB1:                                              ; preds = %BB1, %BB
  %C = icmp ult i16 256, %0
  br i1 true, label %BB1, label %BB2

BB2:                                              ; preds = %BB1
  ret i1 %C
}
```
to
```llvm
define i1 @f(i16 %0) {
  br label %BB1

BB1:                                              ; preds = %BB1, %BB
  %C = icmp ult i16 256, %0
  br i1 true, label %BB1, label %BB2

BB2:                                              ; preds = %BB1
  ret i1 poison
}
```
at which point `%C` becomes dead and can be removed, without having it to sink into BB2 first.

This is a more general solution, which allows us to handle additional cases. For example, cases where we wouldn't sink the instruction due to complex CFG, and cases where the instruction is used both in the dead block and somewhere else, in which case removing the use in the dead block may enable a one-use fold.

https://github.com/llvm/llvm-project/pull/78444


More information about the llvm-commits mailing list