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

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).