public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p
@ 2023-08-16 9:42 bmei at broadcom dot com
2023-08-17 0:19 ` [Bug ipa/111036] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: bmei at broadcom dot com @ 2023-08-16 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111036
Bug ID: 111036
Summary: Code generation error in handling __builtin_constant_p
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: bmei at broadcom dot com
Target Milestone: ---
Compile and run following code
#include <stdio.h>
#define __align(n) __attribute__((aligned(n)))
__attribute__((aligned(32))) static struct {
unsigned long long available_cmd_ids_per_core[2];
} _rl2c_cmd_id_data;
static inline void __attribute__((always_inline))
foo (void *base, size_t length)
{
unsigned long int p = (unsigned long int) base;
if (__builtin_constant_p(p) && (p & 31) == 0) { printf("constant p &&
aligned to 32\n"); }
else if (__builtin_constant_p(length)) { printf("constant length\n");}
else { printf("else\n"); }
}
int main(int argc, char **argv)
{
foo(&_rl2c_cmd_id_data, sizeof(*(&_rl2c_cmd_id_data)));
return 0;
}
With gcc 12.1.0 & gcc 13.1.0, I got segmentation fault. With 11.1.0 and below,
I got correct result. I examined the dumped tree IR. In einline pass, a
__builtin_unreachable is inserted for else if/else branches as the compiler
probably thinks __builtin_constant_p(p) & (p&31) is always true. But the later
passes think __builtin_constant_p(p) is always false. Therefore all code are
optimized away.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/111036] Code generation error in handling __builtin_constant_p
2023-08-16 9:42 [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p bmei at broadcom dot com
@ 2023-08-17 0:19 ` pinskia at gcc dot gnu.org
2023-08-17 0:20 ` pinskia at gcc dot gnu.org
2023-08-20 8:25 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-17 0:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111036
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=99309
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect this is the same bug as PR 99309 just exposed slightly differently.
*** This bug has been marked as a duplicate of bug 99309 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/111036] Code generation error in handling __builtin_constant_p
2023-08-16 9:42 [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p bmei at broadcom dot com
2023-08-17 0:19 ` [Bug ipa/111036] " pinskia at gcc dot gnu.org
@ 2023-08-17 0:20 ` pinskia at gcc dot gnu.org
2023-08-20 8:25 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-17 0:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111036
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|DUPLICATE |---
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reopen as I didn't mean to mark it as a dup just yet.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/111036] Code generation error in handling __builtin_constant_p
2023-08-16 9:42 [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p bmei at broadcom dot com
2023-08-17 0:19 ` [Bug ipa/111036] " pinskia at gcc dot gnu.org
2023-08-17 0:20 ` pinskia at gcc dot gnu.org
@ 2023-08-20 8:25 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-20 8:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111036
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |99309
Known to work| |9.5.0
Status|UNCONFIRMED |NEW
Known to fail| |10.5.0, 11.1.0
Last reconfirmed| |2023-08-20
Ever confirmed|0 |1
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99309
[Bug 99309] [11/12/13/14 Regression] Segmentation fault with
__builtin_constant_p usage at -O2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-20 8:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16 9:42 [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p bmei at broadcom dot com
2023-08-17 0:19 ` [Bug ipa/111036] " pinskia at gcc dot gnu.org
2023-08-17 0:20 ` pinskia at gcc dot gnu.org
2023-08-20 8:25 ` 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).