public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rsandifo at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/22129] [3.4 only] Optimization stomps const, initialized local array Date: Wed, 27 Jul 2005 12:50:00 -0000 [thread overview] Message-ID: <20050727124612.1140.qmail@sourceware.org> (raw) In-Reply-To: <20050620202450.22129.cnewbold@mathworks.com> ------- Additional Comments From rsandifo at gcc dot gnu dot org 2005-07-27 12:46 ------- It'll come as no surprise that this is yet another bug related to the infamous RTX_UNCHANGING_P. A reduced C testcase is: extern void abort (void); void f (const char *x) { if (x[0] + x[1] + x[2] != 6) abort (); } int main() { { struct { int x : 31; char y[5]; } s; s.x = 1; } { const char x[] = { 1, 2, 3 }; f (x); } return 0; } which fails on 3.4 branch for i686-pc-linux-gnu when compiled with "-O2 -fno-strict-aliasing". The problem is that 's.x' and 'x[]' are both stored in the same 32-bit stack slot and that accesses to 'x[]' are marked as unchanging (== "set once"): (insn 18 17 19 (set (mem/s/j:SI (plus:SI (reg/f:SI 54 virtual-stack-vars) (const_int -16 [0xfffffff0])) [0+0 S4 A128]) (reg:SI 58)) -1 (nil) (nil)) .... (insn 25 24 26 (set (mem/s/u:QI (plus:SI (reg/f:SI 54 virtual-stack-vars) (const_int -16 [0xfffffff0])) [0 x+0 S1 A128]) (const_int 1 [0x1])) -1 (nil) (nil)) The scheduler thinks that the two stores don't conflict and decides to swap them around. When using -fstrict-aliasing, the variables will be put into different stack slots and the bug does not occur. This is because can only use the same stack slot for two decls if objects_must_conflict_p says that accesses to them will always conflict. Strict aliasing puts 's' and 'x' into different alias sets, so objects_must_conflict_p will return false. There aren't separate alias sets when using -fno-strict-aliasing, so objects_must_conflict_p lets us assign both decls to the same slot. In a nutshell, the problem seems to be that we're setting RTX_UNCHANGING_P based on the properties of a decl but reusing stack slots based on the properties of a type. (Note that objects_must_conflict_p operates on types rather than decls.) Since RTX_UNCHANGING_P is no more (yay), this bug should be specific to 3.4. I'm really not sure what the best fix there would be. Perhaps we could just get objects_must_conflict_p to return false for arrays of constant elements, much like it does for structures with constant fields? Richard -- What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu dot | |org Status|UNCONFIRMED |NEW Ever Confirmed| |1 Last reconfirmed|0000-00-00 00:00:00 |2005-07-27 12:46:09 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22129
next prev parent reply other threads:[~2005-07-27 12:46 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-06-20 20:25 [Bug c++/22129] New: " cnewbold at mathworks dot com 2005-06-20 20:26 ` [Bug c++/22129] " cnewbold at mathworks dot com 2005-06-20 20:36 ` cnewbold at mathworks dot com 2005-06-20 20:39 ` [Bug rtl-optimization/22129] " pinskia at gcc dot gnu dot org 2005-06-20 20:47 ` cnewbold at mathworks dot com 2005-06-20 20:48 ` [Bug rtl-optimization/22129] [3.4 only] " pinskia at gcc dot gnu dot org 2005-06-20 20:51 ` cnewbold at mathworks dot com 2005-06-21 15:51 ` cnewbold at mathworks dot com 2005-07-27 12:50 ` rsandifo at gcc dot gnu dot org [this message] [not found] <bug-22129-10855@http.gcc.gnu.org/bugzilla/> 2005-10-07 4:06 ` gdr at gcc dot gnu dot org 2006-02-28 15:50 ` gdr at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050727124612.1140.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).