public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp
@ 2023-09-08 21:51 pinskia at gcc dot gnu.org
2023-09-08 21:52 ` [Bug tree-optimization/111346] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08 21:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
Bug ID: 111346
Summary: `X <= MINMAX` pattern is missing :c on the cmp
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: internal-improvement, missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
The pattern:
```
/* X <= MAX(X, Y) -> true
X > MAX(X, Y) -> false
X >= MIN(X, Y) -> true
X < MIN(X, Y) -> false */
(for minmax (min min max max )
cmp (ge lt le gt )
(simplify
(cmp @0 (minmax:c @0 @1))
{ constant_boolean_node (cmp == GE_EXPR || cmp == LE_EXPR, type); } ))
```
Is missing :c on the cmp which causes us to miss:
MAX(X, Y) >= X -> true
etc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
@ 2023-09-08 21:52 ` pinskia at gcc dot gnu.org
2023-09-10 20:52 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2023-09-08
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Have to find a testcase or 2 that fails because of the missing :c though.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
2023-09-08 21:52 ` [Bug tree-optimization/111346] " pinskia at gcc dot gnu.org
@ 2023-09-10 20:52 ` pinskia at gcc dot gnu.org
2023-09-10 23:16 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-10 20:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=96708
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
static inline _Bool
test1 (int a, int b, int c)
{
return c >= a;
}
int f();
int g();
_Bool test2(int a, int b)
{
a = f();
a = g();
int t = a;
if (t < b) t = b;
return test1(a,b,t);
}
```
This should just reduced to:
```
f ();
g ();
return 1;
```
But currently we get:
```
f ();
a_5 = g ();
_3 = MAX_EXPR <a_5, b_6(D)>;
_7 = _3 >= a_5;
return _7;
```
Which does not match the referenced pattern due to the missing :c on cmp.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
2023-09-08 21:52 ` [Bug tree-optimization/111346] " pinskia at gcc dot gnu.org
2023-09-10 20:52 ` pinskia at gcc dot gnu.org
@ 2023-09-10 23:16 ` pinskia at gcc dot gnu.org
2023-09-10 23:18 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-10 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually here is a simplier testcase:
```
_Bool test1(int a, int b)
{
return ((a > b) ? a : b) >= a; // return 1;
}
_Bool test1_(int a, int b)
{
return a <= ((a > b) ? a : b); // return 1;
}
```
Right now test1_ is able to optimize to 1 while test1 is not. but they are both
the same.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-09-10 23:16 ` pinskia at gcc dot gnu.org
@ 2023-09-10 23:18 ` pinskia at gcc dot gnu.org
2023-09-11 2:19 ` cvs-commit at gcc dot gnu.org
2023-09-11 2:20 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-10 23:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55873
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55873&action=edit
Patch which I will commit after testing is finished
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2023-09-10 23:18 ` pinskia at gcc dot gnu.org
@ 2023-09-11 2:19 ` cvs-commit at gcc dot gnu.org
2023-09-11 2:20 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-11 2:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:190cf0ce8f4c141ac5b42d53b9ddeba367495333
commit r14-3832-g190cf0ce8f4c141ac5b42d53b9ddeba367495333
Author: Andrew Pinski <apinski@marvell.com>
Date: Sun Sep 10 15:59:41 2023 -0700
MATCH: [PR111346] `X CMP MINMAX` pattern missing :c on CMP
I noticed this while working on other MINMAX optimizations. It was
hard to find a simplified testcase though because it was dependent on
the ssa name versions. Adding the `:c` to cmp allows the pattern to
be match for the case where minmax as the first operand of the comparison
rather than the second.
Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
PR tree-optimization/111346
gcc/ChangeLog:
* match.pd (`X CMP MINMAX`): Add `:c` on the cmp part
of the pattern
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/minmaxcmp-1.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111346] `X <= MINMAX` pattern is missing :c on the cmp
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2023-09-11 2:19 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11 2:20 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-11 2:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111346
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-09-11 2:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08 21:51 [Bug tree-optimization/111346] New: `X <= MINMAX` pattern is missing :c on the cmp pinskia at gcc dot gnu.org
2023-09-08 21:52 ` [Bug tree-optimization/111346] " pinskia at gcc dot gnu.org
2023-09-10 20:52 ` pinskia at gcc dot gnu.org
2023-09-10 23:16 ` pinskia at gcc dot gnu.org
2023-09-10 23:18 ` pinskia at gcc dot gnu.org
2023-09-11 2:19 ` cvs-commit at gcc dot gnu.org
2023-09-11 2:20 ` pinskia at gcc dot gnu.org
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).