* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
@ 2020-06-04 10:33 ` rguenth at gcc dot gnu.org
2020-06-08 16:47 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-04 10:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |easyhack
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-06-04
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Possibly related clz, ctz, popcount cases (and parity?)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
2020-06-04 10:33 ` [Bug tree-optimization/95527] " rguenth at gcc dot gnu.org
@ 2020-06-08 16:47 ` jakub at gcc dot gnu.org
2020-06-09 6:39 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-08 16:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48705
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48705&action=edit
gcc11-pr95527.patch
Untested fix for ffs. Haven't touched others. I think parity can't be
optimized that way, for ctz/clz we'd need to decide how do we deal with the
undefined at zero fact (vs. e.g. the aarch64 clz/ctz defined already at GIMPLE
to a particular value through *_DEFINED_VALUE_AT_ZERO giving 2).
__builtin_popcount (x) == 0 (and != 0) should be easy, but for that one not
sure if we can optimize much more than that.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
2020-06-04 10:33 ` [Bug tree-optimization/95527] " rguenth at gcc dot gnu.org
2020-06-08 16:47 ` jakub at gcc dot gnu.org
@ 2020-06-09 6:39 ` cvs-commit at gcc dot gnu.org
2021-01-16 11:43 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-09 6:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
--- Comment #3 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:653ab081391e9e7e38b304f3234323c93693d40c
commit r11-1080-g653ab081391e9e7e38b304f3234323c93693d40c
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jun 9 08:38:19 2020 +0200
match.pd: Optimize ffs comparisons against constants [PR95527]
The following patch implements various optimizations of __builtin_ffs*
against constants.
2020-06-09 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/95527
* match.pd (__builtin_ffs (X) cmp CST): New optimizations.
* gcc.dg/tree-ssa/pr95527.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
` (2 preceding siblings ...)
2020-06-09 6:39 ` cvs-commit at gcc dot gnu.org
@ 2021-01-16 11:43 ` jakub at gcc dot gnu.org
2021-04-27 12:48 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-16 11:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For popcount and clz we already have patterns for comparison of the result with
integers.
For ctz not sure what useful simplifications we can do, perhaps just
ctz(x) == bitsize-1 (and !=) to x == 1 << (bitsize-1) (or !=)?
Ah, maybe also inequalifies, ctz(x) >= 3 to (x & ((1 << 3) - 1)) == 0 ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
` (3 preceding siblings ...)
2021-01-16 11:43 ` jakub at gcc dot gnu.org
@ 2021-04-27 12:48 ` cvs-commit at gcc dot gnu.org
2021-08-03 22:21 ` pinskia at gcc dot gnu.org
2021-09-05 0:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-27 12:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
--- Comment #5 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:75f8900159133ce069ef1d2edf3b67c7bc82e305
commit r12-151-g75f8900159133ce069ef1d2edf3b67c7bc82e305
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Apr 27 14:47:54 2021 +0200
match.pd: Add some __builtin_ctz (x) cmp cst simplifications [PR95527]
This patch adds some ctz simplifications (e.g. ctz (x) >= 3 can be done by
testing if the low 3 bits are zero, etc.).
In addition, I've noticed that in the CLZ case, the
#ifdef CLZ_DEFINED_VALUE_AT_ZERO don't really work as intended, they
are evaluated during genmatch and the macro is not defined then
(but, because of the missing tm.h includes it isn't defined in
gimple-match.c or generic-match.c either). And when tm.h is included,
defaults.h is included which defines a fallback version of that macro.
For GCC 12, I wonder if it wouldn't be better to say in addition to
__builtin_c[lt]z*
is always UB at zero that it would be undefined for .C[LT]Z ifn too if it
has just one operand and use a second operand to be the constant we expect
at zero.
2021-04-27 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/95527
* generic-match-head.c: Include tm.h.
* gimple-match-head.c: Include tm.h.
* match.pd (CLZ == INTEGER_CST): Don't use
#ifdef CLZ_DEFINED_VALUE_AT_ZERO, only test
CLZ_DEFINED_VALUE_AT_ZERO
if clz == CFN_CLZ. Add missing val declaration.
(CTZ cmp CST): New simplifications.
* gcc.dg/tree-ssa/pr95527-2.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
` (4 preceding siblings ...)
2021-04-27 12:48 ` cvs-commit at gcc dot gnu.org
@ 2021-08-03 22:21 ` pinskia at gcc dot gnu.org
2021-09-05 0:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 22:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/95527] Failure to optimize __builtin_ffs == 0
2020-06-04 9:42 [Bug tree-optimization/95527] New: Failure to optimize __builtin_ffs == 0 gabravier at gmail dot com
` (5 preceding siblings ...)
2021-08-03 22:21 ` pinskia at gcc dot gnu.org
@ 2021-09-05 0:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-05 0:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95527
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |11.0
Status|NEW |RESOLVED
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 8+ messages in thread