[SimpleLoopUnswitch] unswitch selects
authorJoshua Cao <cao.joshua@yahoo.com>
Sat, 15 Apr 2023 23:04:58 +0000 (16:04 -0700)
committerJoshua Cao <cao.joshua@yahoo.com>
Sun, 30 Apr 2023 04:24:26 +0000 (21:24 -0700)
commite479ed90b591c18873fda68c12946b9d08cbe02f
treef852b926e3edd4a16fb9c26564bf60003cc6cd0c
parent831c221e62b4c8f2efff519cb626b2b3a335b2dd
[SimpleLoopUnswitch] unswitch selects

The old LoopUnswitch pass unswitched selects, but the changes were never
ported to the new SimpleLoopUnswitch.

We unswitch by turning:

```
S = select %cond, %a, %b
```

into:

```
head:
br %cond, label %then, label %tail

then:
br label %tail

tail:
S = phi [ %a, %then ], [ %b, %head ]
```

Unswitch selects are always nontrivial, since the successors do not exit
the loop and the loop body always needs to be cloned.

Differential Revision: https://reviews.llvm.org/D138526

Co-authored-by: Sergey Kachkov <sergey.kachkov@syntacore.com>
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-select.ll
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-trivial-select.ll