[all-commits] [llvm/llvm-project] 21f226: [SimpleLoopUnswitch] unswitch selects

Joshua Cao via All-commits all-commits at lists.llvm.org
Wed May 10 00:43:37 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 21f226fc4591db6e98faf380137a42067c909582
      https://github.com/llvm/llvm-project/commit/21f226fc4591db6e98faf380137a42067c909582
  Author: Joshua Cao <cao.joshua at yahoo.com>
  Date:   2023-05-10 (Wed, 10 May 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-select.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-trivial-select.ll

  Log Message:
  -----------
  [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.

Unswitch selects always need to freeze the conditional if the
conditional could be poison or undef. Selects don't propagate
poison/undef, and branches on poison/undef causes UB.

Reviewed By: nikic, kachkov98, vitalybuka

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




More information about the All-commits mailing list