[SimpleLoopUnswitch] Unswitch AND/OR conditions of selects
authorJoshua Cao <cao.joshua@yahoo.com>
Tue, 30 May 2023 03:57:20 +0000 (20:57 -0700)
committerJoshua Cao <cao.joshua@yahoo.com>
Wed, 14 Jun 2023 07:52:45 +0000 (00:52 -0700)
commit2f171b275f71f5f753980bfcbb2b1aeaa2b3701a
tree29ec790c2146a021cd6f40b06d9f389a3b090ff4
parent67d4538a81f89108c23369c7e8385b88185ad0a2
[SimpleLoopUnswitch] Unswitch AND/OR conditions of selects

If a select's condition is a AND/OR, we can unswitch invariant operands.
This patch uses existing logic from unswitching AND/OR's for branch
conditions.

This patch fixes the Cost computation for unswitching selects to have
the cost of the entire loop, since unswitching selects do not remove
branches. This is required for this patch because otherwise, there are
cases where unswitching selects of AND/OR is beating out unswitching of
branches.

This patch also prevents unswitching of logical AND/OR selects. This
should instead be done by unswitching of AND/OR branch conditions.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D151677
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