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
- 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.
- 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.