]> git.ipfire.org Git - thirdparty/gcc.git/commit
[committed] [PR tree-optimization/110199] Simplify MIN/MAX more often
authorjlaw <jeffreyalaw@gmail.com>
Sun, 10 Mar 2024 17:58:00 +0000 (11:58 -0600)
committerjlaw <jeffreyalaw@gmail.com>
Sun, 10 Mar 2024 18:03:52 +0000 (12:03 -0600)
commit8fe27ed193d60f6cd8b34761858a720c95eabbdb
tree40695c03bebeee3a971d5c259ec48960934d967b
parent993c6de642ffeb2867edbe80ff2a72c0a2eb604e
[committed] [PR tree-optimization/110199] Simplify MIN/MAX more often

So as I mentioned in the BZ, the case of

t = MIN_EXPR (A, B)

where we know something about the relationship between A and B can be trivially
handled by some existing code in DOM.  That existing code would simplify when A
== B.  But by testing GE and LE instead of EQ we can cover more cases with
minimal effort.  When applicable the MIN/MAX turns into a simple copy.

I made one other change.  We have other binary operations that we simplify when
we know something about the relationship between the operands.  That code was
not canonicalizing the order of operands when building the expression to lookup
in the hash tables to discover that relationship.  Since those paths are only
testing for equality, we can trivially reverse them and not have to worry about
changing codes or anything like that.  So extremely safe and avoids having to
come back and fix that code to match the MIN_EXPR/MAX_EXPR case later.

Bootstrapped on x86 and also tested on the crosses.  I briefly thought there
was an sh regression, but that was actually the recent fwprop changes twiddling
code generation for one test.

PR tree-optimization/110199
gcc/
* tree-ssa-scopedtables.cc
(avail_exprs_stack::simplify_binary_operation): Generalize handling
of MIN_EXPR/MAX_EXPR to allow additional simplifications.  Canonicalize
comparison operands for other cases.

gcc/testsuite

* gcc.dg/tree-ssa/minmax-27.c: New test.
* gcc.dg/tree-ssa/minmax-28.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/minmax-27.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/minmax-28.c [new file with mode: 0644]
gcc/tree-ssa-scopedtables.cc