[PATCH] D143726: [LoopInstSimplify] Simplify (X < A && X < B) into (X < MIN(A, B)) if MIN(A, B) is loop-invariant

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 10 04:38:11 PST 2023


mkazantsev created this revision.
mkazantsev added reviewers: skatkov, fhahn, asbirlea, chandlerc, apilipenko.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We don't do this transform in InstCombine in general case for arbitrary values, because cost of
AND and 2 ICMP's isn't higher than of MIN and ICMP. However, LoopInstSimplify also has a notion
about the loop structure. This transform becomes profitable if `A` and `B` are loop-invariant and
`X` is not: by doing this, we can compute min outside the loop.


https://reviews.llvm.org/D143726

Files:
  llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
  llvm/test/Transforms/LoopInstSimplify/loop_invariant.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143726.496427.patch
Type: text/x-patch
Size: 23054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230210/44070cad/attachment.bin>


More information about the llvm-commits mailing list