public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
@ 2020-06-17 21:58 gabravier at gmail dot com
2020-06-18 8:41 ` [Bug tree-optimization/95731] " rguenth at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: gabravier at gmail dot com @ 2020-06-17 21:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Bug ID: 95731
Summary: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(int a, int b)
{
return a >= 0 && b >= 0;
}
This can be optimized to `return (a | b) >= 0;`. LLVM does this transformation,
but GCC does not.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
@ 2020-06-18 8:41 ` rguenth at gcc dot gnu.org
2020-06-18 9:19 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18 8:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |easyhack,
| |missed-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Two pieces depending on SHORT_CIRCUIT_...
maybe_fold_and_comparisons for ifcombine and a match.pd pattern for
_1 = a_3(D) >= 0;
_2 = b_4(D) >= 0;
_5 = _1 & _2;
that should also make it work through maybe_fold_and_comparisons. We have
something like this in fold-const.c btw.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
2020-06-18 8:41 ` [Bug tree-optimization/95731] " rguenth at gcc dot gnu.org
@ 2020-06-18 9:19 ` jakub at gcc dot gnu.org
2020-08-04 11:21 ` wilco at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-18 9:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Or reassoc could do it across different BBs.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
2020-06-18 8:41 ` [Bug tree-optimization/95731] " rguenth at gcc dot gnu.org
2020-06-18 9:19 ` jakub at gcc dot gnu.org
@ 2020-08-04 11:21 ` wilco at gcc dot gnu.org
2020-08-04 11:30 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: wilco at gcc dot gnu.org @ 2020-08-04 11:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Wilco <wilco at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-08-04
CC| |wilco at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #3 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Gabriel Ravier from comment #0)
> bool f(int a, int b)
> {
> return a >= 0 && b >= 0;
> }
>
> This can be optimized to `return (a | b) >= 0;`. LLVM does this
> transformation, but GCC does not.
For orthogonality you also want:
a < 0 && b < 0 -> (a & b) < 0
a >= 0 || b >= 0 -> (a & b) >= 0
a < 0 || b < 0 -> (a | b) < 0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (2 preceding siblings ...)
2020-08-04 11:21 ` wilco at gcc dot gnu.org
@ 2020-08-04 11:30 ` jakub at gcc dot gnu.org
2021-01-11 14:44 ` [Bug tree-optimization/95731] Failure " jakub at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-04 11:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think doing it only in the last reassoc would have the advantage that it
wouldn't break other optimizations done by reassoc.
E.g.
if (a >= 0 && b >= 0 && a < 32 && b < 128)
which can be now optimized into a < 32U && b < 128U couldn't be optimized
unless we teach the reassoc code that (a | b) >= 0 is equivalent to a >= 0 && b
>= 0.
The user can write it that way though:
void bar (int, int);
void
foo (int a, int b)
{
if (a >= 0 && b >= 0 && a < 32 && b < 128)
bar (a, b);
}
void
baz (int a, int b)
{
if ((a | b) >= 0 && a < 32 && b < 128)
bar (a, b);
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Failure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (3 preceding siblings ...)
2020-08-04 11:30 ` jakub at gcc dot gnu.org
@ 2021-01-11 14:44 ` jakub at gcc dot gnu.org
2021-01-12 10:05 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-11 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49938
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49938&action=edit
gcc11-pr95731.patch
Untested fix.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Failure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (4 preceding siblings ...)
2021-01-11 14:44 ` [Bug tree-optimization/95731] Failure " jakub at gcc dot gnu.org
@ 2021-01-12 10:05 ` cvs-commit at gcc dot gnu.org
2021-01-16 8:42 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-12 10:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:13d47c37a2c043f3e5981e73e4c82158a39f41e8
commit r11-6609-g13d47c37a2c043f3e5981e73e4c82158a39f41e8
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jan 12 11:03:40 2021 +0100
reassoc: Optimize in reassoc x < 0 && y < 0 to (x | y) < 0 etc. [PR95731]
We already had x != 0 && y != 0 to (x | y) != 0 and
x != -1 && y != -1 to (x & y) != -1 and
x < 32U && y < 32U to (x | y) < 32U, this patch adds signed
x < 0 && y < 0 to (x | y) < 0. In that case, the low/high seem to be
always the same and just in_p indices whether it is >= 0 or < 0,
also, all types in the same bucket (same precision) should be type
compatible, but we can have some >= 0 and some < 0 comparison mixed,
so the patch handles that by using the right BIT_IOR_EXPR or BIT_AND_EXPR
and doing one set of < 0 or >= 0 first, then BIT_NOT_EXPR and then the
other
one. I had to move optimize_range_tests_var_bound before this optimization
because that one deals with signed a >= 0 && a < b, and limited it to the
last reassoc pass as reassoc itself can't virtually undo this optimization
yet (and not sure if vrp would be able to).
2021-01-12 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/95731
* tree-ssa-reassoc.c (optimize_range_tests_cmp_bitwise): Also
optimize
x < 0 && y < 0 && z < 0 into (x | y | z) < 0 for signed x, y, z.
(optimize_range_tests): Call optimize_range_tests_cmp_bitwise
only after optimize_range_tests_var_bound.
* gcc.dg/tree-ssa/pr95731.c: New test.
* gcc.c-torture/execute/pr95731.c: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Failure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (5 preceding siblings ...)
2021-01-12 10:05 ` cvs-commit at gcc dot gnu.org
@ 2021-01-16 8:42 ` jakub at gcc dot gnu.org
2021-08-14 21:27 ` pinskia at gcc dot gnu.org
2021-08-14 21:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-16 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Failure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (6 preceding siblings ...)
2021-01-16 8:42 ` jakub at gcc dot gnu.org
@ 2021-08-14 21:27 ` pinskia at gcc dot gnu.org
2021-08-14 21:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-14 21:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/95731] Failure to optimize a >= 0 && b >= 0 to (a | b) >= 0
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
` (7 preceding siblings ...)
2021-08-14 21:27 ` pinskia at gcc dot gnu.org
@ 2021-08-14 21:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-14 21:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95731
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla@poradnik-webmaster
| |a.com
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 83123 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-08-14 21:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 21:58 [Bug tree-optimization/95731] New: Faiilure to optimize a >= 0 && b >= 0 to (a | b) >= 0 gabravier at gmail dot com
2020-06-18 8:41 ` [Bug tree-optimization/95731] " rguenth at gcc dot gnu.org
2020-06-18 9:19 ` jakub at gcc dot gnu.org
2020-08-04 11:21 ` wilco at gcc dot gnu.org
2020-08-04 11:30 ` jakub at gcc dot gnu.org
2021-01-11 14:44 ` [Bug tree-optimization/95731] Failure " jakub at gcc dot gnu.org
2021-01-12 10:05 ` cvs-commit at gcc dot gnu.org
2021-01-16 8:42 ` jakub at gcc dot gnu.org
2021-08-14 21:27 ` pinskia at gcc dot gnu.org
2021-08-14 21:28 ` 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).