public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
@ 2023-06-06 1:50 pinskia at gcc dot gnu.org
2023-06-06 1:59 ` [Bug tree-optimization/110134] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 1:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
Bug ID: 110134
Summary: [10/11/12/13/14 Regression] (-unsigned1) != CST is not
optimized to unsigned1 != CST at the gimple level
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization, TREE
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
bool f1(int a)
{
unsigned t = a < 10;
t = -t;
return t != 0;
}
bool f2(int a)
{
signed t = a < 10;
t = -t;
return t != 0;
}
```
These should both optimize to just `a >= 9` in forwprop1 .
Both of these were working in GCC 5.
Starting GCC 6, neither was done and then in GCC 8, f2 was handled.
I noticed this while looking at PR 110131 (doing this does not fix that
though).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
@ 2023-06-06 1:59 ` pinskia at gcc dot gnu.org
2023-06-06 2:08 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 1:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2023-06-06
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have a simple patch.
TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
Can just be:
(cmp == EQ_EXPR || cmp == NE_EXPR || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
For /* -A CMP -B -> B CMP A. */
Because -a == -b is still a == b, no matter what.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
2023-06-06 1:59 ` [Bug tree-optimization/110134] " pinskia at gcc dot gnu.org
@ 2023-06-06 2:08 ` pinskia at gcc dot gnu.org
2023-06-06 2:50 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 2:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is:
```
/* -A CMP -B -> B CMP A. */
(for cmp (tcc_comparison)
scmp (swapped_tcc_comparison)
(simplify
(cmp (negate @0) (negate @1))
(if (FLOAT_TYPE_P (TREE_TYPE (@0))
|| (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& (cmp == EQ_EXPR
|| cmp == NE_EXPR
|| TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))))
(scmp @0 @1)))
(simplify
(cmp (negate @0) CONSTANT_CLASS_P@1)
(if (FLOAT_TYPE_P (TREE_TYPE (@0))
|| (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& (cmp == EQ_EXPR
|| cmp == NE_EXPR
|| TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))))
(with { tree tem = const_unop (NEGATE_EXPR, TREE_TYPE (@0), @1); }
(if (tem && !TREE_OVERFLOW (tem))
(scmp @0 { tem; }))))))
```
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
2023-06-06 1:59 ` [Bug tree-optimization/110134] " pinskia at gcc dot gnu.org
2023-06-06 2:08 ` pinskia at gcc dot gnu.org
@ 2023-06-06 2:50 ` pinskia at gcc dot gnu.org
2023-06-06 8:36 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 2:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
r6-1814-g66e1cacf608045 caused GCC 6 to stop doing both.
Because they were considered redundant with the patterns added by:
r6-1113-g534bd33b61d08e
Which was mostly true.
I think forwprop was working again with r8-2194-g4f450a2b102212 for f2 (I am
not 100% sure).
So to summarize r6-1814-g66e1cacf608045 removed the unsigned/wrapping case for
NE/EQ since it was originally thought as redundant. My patch adds support back
for those 2.
case EQ_EXPR:
case NE_EXPR:
...
- /* Similarly for a NEGATE_EXPR. */
- if (TREE_CODE (arg0) == NEGATE_EXPR
- && TREE_CODE (arg1) == INTEGER_CST
- && 0 != (tem = negate_expr (fold_convert_loc (loc, TREE_TYPE (arg0),
- arg1)))
- && TREE_CODE (tem) == INTEGER_CST
- && !TREE_OVERFLOW (tem))
- return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
...
- /* Fold -X op -Y as X op Y, where op is eq/ne. */
- if (TREE_CODE (arg0) == NEGATE_EXPR
- && TREE_CODE (arg1) == NEGATE_EXPR)
- return fold_build2_loc (loc, code, type,
- TREE_OPERAND (arg0, 0),
- fold_convert_loc (loc, TREE_TYPE (arg0),
- TREE_OPERAND (arg1, 0)));
Since these 2 did cases didn't test TYPE_OVERFLOW_UNDEFINED, we should handle
EQ/NE also in match.pd the same way.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-06-06 2:50 ` pinskia at gcc dot gnu.org
@ 2023-06-06 8:36 ` rguenth at gcc dot gnu.org
2023-06-06 21:11 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-06 8:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
Target Milestone|--- |10.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2023-06-06 8:36 ` rguenth at gcc dot gnu.org
@ 2023-06-06 21:11 ` pinskia at gcc dot gnu.org
2023-06-07 2:59 ` cvs-commit at gcc dot gnu.org
2023-06-07 3:02 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-06 21:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-June/62
| |0818.html
Keywords| |patch
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch submitted with a few testcases to make sure it will not regress again:
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/620818.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2023-06-06 21:11 ` pinskia at gcc dot gnu.org
@ 2023-06-07 2:59 ` cvs-commit at gcc dot gnu.org
2023-06-07 3:02 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07 2:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
--- 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:cc155ff9c38848a8e6a7125dd0b66ac0aef47880
commit r14-1599-gcc155ff9c38848a8e6a7125dd0b66ac0aef47880
Author: Andrew Pinski <apinski@marvell.com>
Date: Mon Jun 5 19:12:43 2023 -0700
For the `-A CMP -B -> B CMP A` pattern allow EQ/NE for all integer types
I noticed while looking at some code generation issue, that forwprop
was not handling `-a == 0` for unsigned types and I was confused why
it was not.
r6-1814-g66e1cacf608045 removed these from fold because they
were supposed to be already handled by the match.pd patterns
but it was missed that the match.pd patterns checked
TYPE_OVERFLOW_UNDEFINED while fold didn't do that for NE/EQ.
This patch removes the restriction on NE/EQ on TYPE_OVERFLOW_UNDEFINED.
OK? Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
PR tree-optimization/110134
* match.pd (-A CMP -B -> B CMP A): Allow EQ/NE for all integer
types.
(-A CMP CST -> B CMP (-CST)): Likewise.
gcc/testsuite/ChangeLog:
PR tree-optimization/110134
* gcc.dg/tree-ssa/negneq-1.c: New test.
* gcc.dg/tree-ssa/negneq-2.c: New test.
* gcc.dg/tree-ssa/negneq-3.c: New test.
* gcc.dg/tree-ssa/negneq-4.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/110134] [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
` (5 preceding siblings ...)
2023-06-07 2:59 ` cvs-commit at gcc dot gnu.org
@ 2023-06-07 3:02 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-07 3:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110134
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Target Milestone|10.5 |14.0
Resolution|--- |FIXED
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on the trunk for GCC 14, the performance regression due to this bug I
doubt is noticable since it had not been noticed since GCC 6 even (well PR
14753 noticed it but it was similar to this one, it was not noticed in real
code yet).
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-06-07 3:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 1:50 [Bug tree-optimization/110134] New: [10/11/12/13/14 Regression] (-unsigned1) != CST is not optimized to unsigned1 != CST at the gimple level pinskia at gcc dot gnu.org
2023-06-06 1:59 ` [Bug tree-optimization/110134] " pinskia at gcc dot gnu.org
2023-06-06 2:08 ` pinskia at gcc dot gnu.org
2023-06-06 2:50 ` pinskia at gcc dot gnu.org
2023-06-06 8:36 ` rguenth at gcc dot gnu.org
2023-06-06 21:11 ` pinskia at gcc dot gnu.org
2023-06-07 2:59 ` cvs-commit at gcc dot gnu.org
2023-06-07 3:02 ` 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).