[LICM] Simplify (X < A && X < B) into (X < MIN(A, B)) if MIN(A, B) is loop-invariant
authorMax Kazantsev <mkazantsev@azul.com>
Mon, 20 Feb 2023 10:24:49 +0000 (17:24 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Fri, 10 Mar 2023 10:36:52 +0000 (17:36 +0700)
commit6b03ce374e0dc64868b4b6665056dfc3fda0e98f
tree8555312782cc86f1ecd2c86840a57fc9532ce315
parent946f8030b58d3d6975369c1b8e047385b86c7ab0
[LICM] Simplify (X < A && X < B) into (X < MIN(A, B)) if MIN(A, B) is loop-invariant

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

Differential Revision: https://reviews.llvm.org/D143726
Reviewed By: nikic
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/CodeGen/AMDGPU/wave32.ll
llvm/test/CodeGen/PowerPC/sms-cpy-1.ll
llvm/test/Transforms/LICM/min_max.ll