public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern
@ 2020-12-15 21:54 gabravier at gmail dot com
2021-11-25 22:33 ` [Bug tree-optimization/98304] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-12-15 21:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
Bug ID: 98304
Summary: Failure to optimize bitwise arithmetic pattern
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: ---
int f1(int n)
{
return n - (((n > 63) ? n : 63) & -64);
}
This can be optimized to `return (n <= 63) ? n : (n & 63);` (and presumably the
same optimization should be doable with other powers of 2).
PS: I found this optimization while looking at how this :
int f1(int n)
{
while (n >= 64)
n -= 64;
return n;
}
is optimized. LLVM outputs the first example I gave here, while GCC outputs the
optimization I gave here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98304] Failure to optimize bitwise arithmetic pattern
2020-12-15 21:54 [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern gabravier at gmail dot com
@ 2021-11-25 22:33 ` pinskia at gcc dot gnu.org
2021-11-25 22:39 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-25 22:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-11-25
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
_1 = MAX_EXPR <n_3(D), 63>;
_2 = _1 & -64;
_4 = n_3(D) - _2;
Something like:
(simplify
(minus @0 (bit_and (max @0 INTEGER_CST@1) INTEGER_CST@2))
(if (@1 == (@2)-1)
(if (TYPE_SIGN (type) == UNSIGNED)
(bit_and @0 @1)
(cond (le @0 @1) @0 (bit_and @0 @1))
)
)
)
Note LLVM handles the unsigned case already.
Also note also even though GCC can handle the loop case for signed, it only
handles it on the RTL level, for gimple GCC produces:
_3 = n_2(D) + -64;
_8 = (unsigned int) n_2(D);
_9 = _8 + 4294967232; // _9 = _3 - 64
_10 = _9 >> 6; // _10 = _9/64
_11 = (int) _10;
_12 = _11 * -64;
n_1 = _3 + _12;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98304] Failure to optimize bitwise arithmetic pattern
2020-12-15 21:54 [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern gabravier at gmail dot com
2021-11-25 22:33 ` [Bug tree-optimization/98304] " pinskia at gcc dot gnu.org
@ 2021-11-25 22:39 ` pinskia at gcc dot gnu.org
2022-07-09 16:08 ` cvs-commit at gcc dot gnu.org
2023-09-17 5:58 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-25 22:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> @1 == (@2)-1
Should have been:
@1 == -(@2-1)
maybe check that @1 is a mask.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98304] Failure to optimize bitwise arithmetic pattern
2020-12-15 21:54 [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern gabravier at gmail dot com
2021-11-25 22:33 ` [Bug tree-optimization/98304] " pinskia at gcc dot gnu.org
2021-11-25 22:39 ` pinskia at gcc dot gnu.org
@ 2022-07-09 16:08 ` cvs-commit at gcc dot gnu.org
2023-09-17 5:58 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-09 16:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <law@gcc.gnu.org>:
https://gcc.gnu.org/g:d9fa599dc7584d89e758a09a3d68982f12d8751c
commit r13-1587-gd9fa599dc7584d89e758a09a3d68982f12d8751c
Author: Sam Feifer <sfeifer@redhat.com>
Date: Sat Jul 9 12:08:01 2022 -0400
[PATCH] match.pd: Add new bitwise arithmetic pattern [PR98304]
PR tree-optimization/98304
gcc:
* match.pd (n - (((n > C1) ? n : C1) & -C2)): New simplification.
gcc/testsuite:
* gcc.c-torture/execute/pr98304-2.c: New test.
* gcc.dg/pr98304-1.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98304] Failure to optimize bitwise arithmetic pattern
2020-12-15 21:54 [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern gabravier at gmail dot com
` (2 preceding siblings ...)
2022-07-09 16:08 ` cvs-commit at gcc dot gnu.org
@ 2023-09-17 5:58 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-17 5:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-17 5:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 21:54 [Bug tree-optimization/98304] New: Failure to optimize bitwise arithmetic pattern gabravier at gmail dot com
2021-11-25 22:33 ` [Bug tree-optimization/98304] " pinskia at gcc dot gnu.org
2021-11-25 22:39 ` pinskia at gcc dot gnu.org
2022-07-09 16:08 ` cvs-commit at gcc dot gnu.org
2023-09-17 5:58 ` 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).