[SCEV] Canonicalize ext(min/max(x, y)) to min/max(ext(x), ext(y))
authorMax Kazantsev <mkazantsev@azul.com>
Mon, 20 Feb 2023 08:48:05 +0000 (15:48 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Mon, 20 Feb 2023 09:12:58 +0000 (16:12 +0700)
commit5fe915bb8c6b963be9c8617fa50aa4d9c1e304fc
treed470c05b1375d560d33667fb2d803c76d637d81a
parent5e111eb275eee3bec1123b4b85606328017e5ee5
[SCEV] Canonicalize ext(min/max(x, y)) to min/max(ext(x), ext(y))

I stumbled over this while trying to improve our exit count work. These expressions
are equivalent for complementary signed/unsigned ext and min/max (including umin_seq),
but they are not canonicalized and SCEV cannot recognize them as the same.

The benefit of this canonicalization is that SCEV can prove some new equivalences which
it coudln't prove because of different forms. There is 1 test where trip count seems pessimized,
I could not directly figure out why, but it just seems an unrelated issue that we can fix.
Other changes seem neutral or positive to me.

Differential Revision: https://reviews.llvm.org/D141481
Reviewed By: nikic
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/ext_min_max.ll
llvm/test/Analysis/ScalarEvolution/fold.ll
llvm/test/Analysis/ScalarEvolution/logical-operations.ll
llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info-rewrite-expressions.ll
llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
llvm/test/Analysis/ScalarEvolution/range_nw_flag.ll