MATCH: [PR111348] add missing :c to cmp in the (a CMP b) ? minmax<a, c> : minmax<b, c> pattern

When I added this pattern in r14-337-gc43819a9b4cd, I had missed the :c on the cmp
part of the pattern meaning there might be some missing optimizations happening.
The testcase shows an example of the missed optmization.

Committed as obvious after a bootstrap/test on x86_64-linux-gnu.

	PR tree-optimization/111348

gcc/ChangeLog:

	* match.pd (`(a CMP b) ? minmax<a, c> : minmax<b, c>`): Add :c on
	the cmp part of the pattern.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/minmax-26.c: New test.
This commit is contained in:
Andrew Pinski 2023-09-11 08:05:10 -07:00
parent 048927ed85
commit 8fdf712a38
2 changed files with 23 additions and 1 deletions

View file

@ -5417,7 +5417,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for minmax (min max)
(for cmp (lt le gt ge ne)
(simplify
(cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4))
(cond (cmp:c @1 @3) (minmax:c @1 @4) (minmax:c @2 @4))
(with
{
tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3);

View file

@ -0,0 +1,22 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-original" } */
/* PR tree-optimization/111348 */
int test1(int a, int b, int c)
{
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
}
int test1_(int a, int b, int c)
{
return (b < a) ? ((a > c) ? a : c) : ((b > c) ? b : c);
}
/* test1 and test1_ should be able to optimize to `MAX_EXPR <MAX_EXPR <a, b>, c>;` during fold. */
/* { dg-final { scan-tree-dump-times "MAX_EXPR <MAX_EXPR <a, b>, c>" 2 "original" } } */
/* { dg-final { scan-tree-dump-not "b > a" "original" } } */
/* { dg-final { scan-tree-dump-not "a > b" "original" } } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR " 4 "optimized" } } */
/* { dg-final { scan-tree-dump-not "if " "optimized" } } */