From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 981A63858C52; Wed, 16 Aug 2023 09:42:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 981A63858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692178923; bh=tw/4otbqy6zhj67aR2Erw6O2rC/wfdRNuQij5dbHs+o=; h=From:To:Subject:Date:From; b=HeFygGTcCjy6kUJb2+4TPwX7pCMRm9i3FB6Z+z3gXxEGF+bFjwUCXBH9KiT9J9FFI qDfY65/pb06Nhnd6PPhf6e6HsfgxVT0w2bk7gJ83J64l4yv8qktmf6q8RGHdGYUHUr f4v+liKsW6/+WTCQ4CfVVZJ+sAmLHh91RpbIhEs0= From: "bmei at broadcom dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111036] New: Code generation error in handling __builtin_constant_p Date: Wed, 16 Aug 2023 09:42:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bmei at broadcom dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111036 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 #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 =3D (unsigned long int) base; if (__builtin_constant_p(p) && (p & 31) =3D=3D 0) { printf("constant p = && aligned to 32\n"); }=20 else if (__builtin_constant_p(length)) { printf("constant length\n");}= =20 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 be= low, 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 la= ter passes think __builtin_constant_p(p) is always false. Therefore all code are optimized away.=