[PATCH] D138526: [SimpleLoopUnswitch] unswitch select instructions

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 15:14:37 PST 2022


caojoshua created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
caojoshua added a reviewer: fhahn.
caojoshua updated this revision to Diff 477304.
caojoshua added a comment.
caojoshua updated this revision to Diff 477305.
caojoshua edited the summary of this revision.
caojoshua added a comment.
caojoshua updated this revision to Diff 477306.
caojoshua edited the summary of this revision.
caojoshua updated this revision to Diff 477319.
caojoshua published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

update commit message


caojoshua added a comment.

Fix typo in commit message


caojoshua added a comment.

More changes before sending for review


Fixes https://github.com/llvm/llvm-project/issues/58122

The old LoopUnswitch pass unswitched selects, but the new
SimpleLoopUnswitch only unswitches branches and switches. Seems selects
were just forgotten or never implemented.

We consider select unswitching to be nontrivial. Trivial switches have
all branches except for one that exit the loop and do not increase code
size. Select unswitches will always produces two branches and always
increase code size.

As a followup, we can try removing trivial select checks in nontrivial
unswitching, and assume select unswitching will cover it. This change
modifies some existing tests that include selects. These changes all
look like an improvement.

There can be improvements in how we compute select unswitch costs. We
assume that select unswitching copies the entire loop. This is not true
when a branch in the loop uses the select, and gets folded into an
unconditional branch.

Refactorings:

- bunch of variable renames
- Replace the array of DomTreeUpdates with DomTreeUpdater. I think its the same thing, since we update all changes at once with the lazy strategy. This is required because ConstantFoldTerminator takes a DomTreeUpdater.

Testing:

- copied in tests that include select from the old LoopUnswitch
- added new @cant_unswitch test for a select with a variant condition
- add some CHECK's for unswitched select instructions in existing tests
- rewrite expected output of some tests that include selects
- @test_partial_unswitch_all_conds_guaranteed_non_poison is optimized correctly, but looks awkward. If the select instruction is moved outside the loop from LICM, which always happens in default -O3 passes, the resulting IR is much smaller. I'm not changing the test because its still correct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138526

Files:
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/2010-11-18-LCSSA.ll
  llvm/test/Transforms/SimpleLoopUnswitch/2012-05-20-Phi.ll
  llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
  llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-trivial-select.ll
  llvm/test/Transforms/SimpleLoopUnswitch/pr32818.ll
  llvm/test/Transforms/SimpleLoopUnswitch/unswitch-equality-undef.ll
  llvm/test/Transforms/SimpleLoopUnswitch/unswitch-select.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138526.477319.patch
Type: text/x-patch
Size: 34014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221122/ca5917e4/attachment-0001.bin>


More information about the llvm-commits mailing list