[all-commits] [llvm/llvm-project] 5cfb9a: [SimpleLoopUnswitch][reland 2] unswitch selects

Joshua Cao via All-commits all-commits at lists.llvm.org
Thu May 11 22:21:12 PDT 2023


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

  Changed paths:
    M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    M llvm/test/Transforms/SimpleLoopUnswitch/crash.ll
    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][reland 2] 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.

Reland 1 - Fix the insertion of freeze instructions. The original
implementation inserts a dead freeze instruction that is not used by the
unswitched branch.

Reland 2 - Include https://reviews.llvm.org/D149560 in the same patch,
which was originally reverted along with this patch. The patch prevents
unswitching of selects with a vector conditional. This could have been
caught in SimpleLoopUnswitch/crash.ll if it included tests for
nontrivial unswitching. This reland also adds a run for the test file
with nontrivial unswitching.

Reviewed By: nikic, kachkov98, vitalybuka

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




More information about the All-commits mailing list