public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
@ 2022-10-03 19:40 pinskia at gcc dot gnu.org
2022-10-06 10:02 ` [Bug tree-optimization/107137] " rguenth at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-03 19:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Bug ID: 107137
Summary: (unsigned)-(int)(bool_var) should be optimized to
-(unsigned)bool_var
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
unsigned f(_Bool a)
{
int t = a;
t = -t;
return t;
}
```
Currently we get:
```
t_2 = (int) a_1(D);
t_3 = -t_2;
_4 = (unsigned int) t_3;
```
But we can do better than that with just:
```
_ = (unsigned int) a_1(D);
_4 = -_;
```
Noticed that while looking into
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107131.
Note even bool_var could be an unsigned type or a type which whos size is
bigger than the outer type really.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
@ 2022-10-06 10:02 ` rguenth at gcc dot gnu.org
2022-11-26 20:45 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-10-06 10:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-10-06
Status|UNCONFIRMED |NEW
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
2022-10-06 10:02 ` [Bug tree-optimization/107137] " rguenth at gcc dot gnu.org
@ 2022-11-26 20:45 ` pinskia at gcc dot gnu.org
2023-08-31 18:34 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-26 20:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=107765
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Related to PR 107765 (but not exactly a dup).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
2022-10-06 10:02 ` [Bug tree-optimization/107137] " rguenth at gcc dot gnu.org
2022-11-26 20:45 ` pinskia at gcc dot gnu.org
@ 2023-08-31 18:34 ` pinskia at gcc dot gnu.org
2023-09-01 2:27 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-31 18:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-08-31 18:34 ` pinskia at gcc dot gnu.org
@ 2023-09-01 2:27 ` pinskia at gcc dot gnu.org
2023-09-01 16:26 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-01 2:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-Septemb
| |er/629018.html
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629018.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2023-09-01 2:27 ` pinskia at gcc dot gnu.org
@ 2023-09-01 16:26 ` pinskia at gcc dot gnu.org
2023-09-02 7:01 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-01 16:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Solving this one is easier, just going with:
/* (nop_outer_cast)-(inner_cast)var -> -(outer_cast)(var)
if var is smaller in precision. */
(simplify
(convert (negate:s@1 (convert:s @0)))
(if (INTEGRAL_TYPE_P (type)
&& tree_nop_conversion_p (type, TREE_TYPE (@1))
&& TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0)))
(negate (convert @0))))
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2023-09-01 16:26 ` pinskia at gcc dot gnu.org
@ 2023-09-02 7:01 ` pinskia at gcc dot gnu.org
2023-09-05 21:16 ` cvs-commit at gcc dot gnu.org
2023-09-05 21:16 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-02 7:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL|https://gcc.gnu.org/piperma |https://gcc.gnu.org/piperma
|il/gcc-patches/2023-Septemb |il/gcc-patches/2023-Septemb
|er/629018.html |er/629156.html
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Updated patch:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629156.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
` (5 preceding siblings ...)
2023-09-02 7:01 ` pinskia at gcc dot gnu.org
@ 2023-09-05 21:16 ` cvs-commit at gcc dot gnu.org
2023-09-05 21:16 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-05 21:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
--- Comment #6 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:e6bcf83989478348428c732c11e6c0f1719e9214
commit r14-3721-ge6bcf83989478348428c732c11e6c0f1719e9214
Author: Andrew Pinski <apinski@marvell.com>
Date: Thu Aug 31 16:17:35 2023 -0700
MATCH: `(nop_convert)-(convert)a` into -(convert)a if we are converting
from something smaller
This allows removal of one conversion and in the case of booleans, might be
able to remove
the negate and the other conversion later on.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/107137
gcc/ChangeLog:
* match.pd (`(nop_convert)-(convert)a`): New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/neg-cast-2.c: New test.
* gcc.dg/tree-ssa/neg-cast-3.c: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/107137] (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
` (6 preceding siblings ...)
2023-09-05 21:16 ` cvs-commit at gcc dot gnu.org
@ 2023-09-05 21:16 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-05 21:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107137
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |14.0
Status|ASSIGNED |RESOLVED
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-09-05 21:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-03 19:40 [Bug tree-optimization/107137] New: (unsigned)-(int)(bool_var) should be optimized to -(unsigned)bool_var pinskia at gcc dot gnu.org
2022-10-06 10:02 ` [Bug tree-optimization/107137] " rguenth at gcc dot gnu.org
2022-11-26 20:45 ` pinskia at gcc dot gnu.org
2023-08-31 18:34 ` pinskia at gcc dot gnu.org
2023-09-01 2:27 ` pinskia at gcc dot gnu.org
2023-09-01 16:26 ` pinskia at gcc dot gnu.org
2023-09-02 7:01 ` pinskia at gcc dot gnu.org
2023-09-05 21:16 ` cvs-commit at gcc dot gnu.org
2023-09-05 21:16 ` 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).