From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 4C06C398AC2B; Tue, 30 Aug 2022 07:01:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C06C398AC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661842911; bh=G/O/SsMMDNT25cacvzGjvxopUoLSZYWKROZEBmvnhJc=; h=From:To:Subject:Date:From; b=lUjhyWddjVijdd+3/UqW+FQnD2eZqRjj2vY2R+WjoNGQToanNj+ndLsZiHDr/g6BM QyPOSBpu+W+XdHWc0Bt0vGkaJSdDp2MxlFZfRLYEcvubpLXbDaFpiRt7tiNzCWYHik anHi8tncF9YhF1iOZX+xuxCiZudoT0SROOmjsYVo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tamar Christina To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2259] middle-end: fix min/max phiopts reduction [PR106744] X-Act-Checkin: gcc X-Git-Author: Tamar Christina X-Git-Refname: refs/heads/master X-Git-Oldrev: 368dbb23c5efaf86b2b18945508d379713c0d12c X-Git-Newrev: 37ebaabde2b88d446369240ae8f03b8e6a284a7b Message-Id: <20220830070151.4C06C398AC2B@sourceware.org> Date: Tue, 30 Aug 2022 07:01:51 +0000 (GMT) List-Id: https://gcc.gnu.org/g:37ebaabde2b88d446369240ae8f03b8e6a284a7b commit r13-2259-g37ebaabde2b88d446369240ae8f03b8e6a284a7b Author: Tamar Christina Date: Tue Aug 30 07:49:02 2022 +0100 middle-end: fix min/max phiopts reduction [PR106744] This corrects the argument usage to use them in the order that they occur in the comparisons in gimple. gcc/ChangeLog: PR tree-optimization/106744 * tree-ssa-phiopt.cc (minmax_replacement): Correct arguments. gcc/testsuite/ChangeLog: PR tree-optimization/106744 * gcc.dg/tree-ssa/minmax-10.c: Make runtime test. * gcc.dg/tree-ssa/minmax-11.c: Likewise. * gcc.dg/tree-ssa/minmax-12.c: Likewise. * gcc.dg/tree-ssa/minmax-13.c: Likewise. * gcc.dg/tree-ssa/minmax-14.c: Likewise. * gcc.dg/tree-ssa/minmax-15.c: Likewise. * gcc.dg/tree-ssa/minmax-16.c: Likewise. * gcc.dg/tree-ssa/minmax-3.c: Likewise. * gcc.dg/tree-ssa/minmax-4.c: Likewise. * gcc.dg/tree-ssa/minmax-5.c: Likewise. * gcc.dg/tree-ssa/minmax-6.c: Likewise. * gcc.dg/tree-ssa/minmax-7.c: Likewise. * gcc.dg/tree-ssa/minmax-8.c: Likewise. * gcc.dg/tree-ssa/minmax-9.c: Likewise. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c | 15 ++++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c | 15 ++++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c | 17 +++++++++++++++-- gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c | 15 ++++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c | 14 +++++++++++++- gcc/tree-ssa-phiopt.cc | 4 ++-- 15 files changed, 189 insertions(+), 17 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c index 58995368441..c9322a17a4a 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-optimized" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -16,5 +17,16 @@ uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_max (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c index 1c2ef01b5d1..b1da41712b3 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c @@ -1,8 +1,10 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-optimized" } */ #include + +__attribute__ ((noipa, noinline)) uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -16,6 +18,17 @@ uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax1 (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c index 3d0c07d9b57..cb9188f90e8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noinline, noipa)) uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -16,5 +17,16 @@ uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax3 (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c index c0d0f27c802..62ba71e8c3f 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -15,5 +16,17 @@ uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) { } return xk; } + +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 127; + volatile uint8_t xc = 0; + if (three_minmax2 (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c index 9c0cadbf7e3..a3ec5846083 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-optimized" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -16,6 +17,17 @@ uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax11 (xc, xm, xy) != 128) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c index 1d97a16564f..8a39871c938 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c @@ -1,10 +1,11 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include #include -uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy, bool m) { +__attribute__ ((noinline, noipa)) +uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc) { @@ -17,5 +18,17 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy, bool m) { return xk; } + +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_min (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c index 89377a2cb34..4febd092d83 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt -g" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc < xm) { @@ -13,5 +14,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_min (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c index de3b2e946e8..2af10776346 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc < xm) { @@ -13,5 +14,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_min (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c index 0b6d667be86..973f39bfed3 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc > xm) { @@ -13,5 +14,16 @@ uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_max (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c index 650601a3cc7..34e4e720511 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc > xm) { @@ -13,5 +14,16 @@ uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax1 (xc, xm, xy) != 127) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c index a628f6d9922..443d68f826d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc > xm) { @@ -13,5 +14,16 @@ uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax3 (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c index cb42412c4ad..7e2a3f08060 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc > xm) { @@ -12,5 +13,17 @@ uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) { } return xk; } + +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax2 (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c index 9cd050e9323..0160e573fef 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-phiopt" } */ #include +__attribute__ ((noinline, noipa)) uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; if (xc < xm) { @@ -13,5 +14,16 @@ uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_minmax11 (xc, xm, xy) != 255) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c index 24f580271c3..0cfb6584588 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c @@ -1,8 +1,9 @@ -/* { dg-do compile } */ +/* { dg-do run } */ /* { dg-options "-O -fdump-tree-optimized" } */ #include +__attribute__ ((noipa, noinline)) uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { uint8_t xk; xc=~xc; @@ -16,5 +17,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) { return xk; } +int +main (void) +{ + volatile uint8_t xy = 255; + volatile uint8_t xm = 0; + volatile uint8_t xc = 127; + if (three_min (xc, xm, xy) != 0) + __builtin_abort (); + return 0; +} + /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "optimized" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index d5f2ba8be1c..925bd7d8853 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -2150,9 +2150,9 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ gimple_seq stmts = NULL; tree phi_result = PHI_RESULT (phi); result = gimple_build (&stmts, locus, minmax, TREE_TYPE (phi_result), - arg0, bound); + arg0, arg1); result = gimple_build (&stmts, locus, ass_code, TREE_TYPE (phi_result), - result, arg1); + result, bound); if (invert) result = gimple_build (&stmts, locus, BIT_NOT_EXPR, TREE_TYPE (phi_result), result);