public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3842] MATCH: [PR111349] add missing :c to cmp in the `(a CMP CST1) ? max<a, CST2> : a` pattern
@ 2023-09-11 14:24 Andrew Pinski
0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-09-11 14:24 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b59e9de990a17bfd5fa7252b76339c35bff7f2e8
commit r14-3842-gb59e9de990a17bfd5fa7252b76339c35bff7f2e8
Author: Andrew Pinski <apinski@marvell.com>
Date: Sun Sep 10 21:58:12 2023 -0700
MATCH: [PR111349] add missing :c to cmp in the `(a CMP CST1) ? max<a,CST2> : a` pattern
When I added this pattern in r14-1411-g17cca3c43e2f49, 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/111349
gcc/ChangeLog:
* match.pd (`(a CMP CST1) ? max<a,CST2> : a`): Add :c on
the cmp part of the pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/minmax-25.c: New test.
Diff:
---
gcc/match.pd | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index a60fe04885e7..209b0599382a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5431,7 +5431,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for cmp (gt ge lt le)
minmax (min min max max)
(simplify
- (cond (cmp @0 @1) (minmax:c@2 @0 @3) @4)
+ (cond (cmp:c @0 @1) (minmax:c@2 @0 @3) @4)
(with
{
tree_code code = minmax_from_comparison (cmp, @0, @1, @0, @4);
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c
new file mode 100644
index 000000000000..b7a5bfd4c193
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original" } */
+/* PR tree-optimization/111349 */
+
+int f();
+int g();
+
+int test1(int a, int b)
+{
+ return (a > b) ? ((a > b) ? a : b) : a;
+}
+
+int test1_(int a, int b)
+{
+ return (b < a) ? ((a > b) ? a : b) : a;
+}
+
+/* test1 and test1_ should be able to optimize to `return a;` during fold. */
+/* { dg-final { scan-tree-dump-times "return a;" 2 "original" } } */
+/* { dg-final { scan-tree-dump-not " MAX_EXPR " "original" } } */
+/* { dg-final { scan-tree-dump-times "return a" 2 "optimized" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-11 14:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-11 14:24 [gcc r14-3842] MATCH: [PR111349] add missing :c to cmp in the `(a CMP CST1) ? max<a, CST2> : a` pattern Andrew Pinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).