public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rahul at icerasemi dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/42614] New: FRE optimizes away valid code after IPA inlining Date: Mon, 04 Jan 2010 18:24:00 -0000 [thread overview] Message-ID: <bug-42614-17160@http.gcc.gnu.org/bugzilla/> (raw) On the following test case compiled with GCC 4.4.1 release version and the following command line gcc -S -O2 -finline-functions-called-once -fdump-tree-all-details -fdump-ipa-all fail.c typedef struct SEntry { unsigned char num; } TEntry; typedef struct STable { TEntry data[2]; } TTable; TTable *init (); int fake_expect (int, int); void fake_assert (int); void expect_func (int a, unsigned char *b) __attribute__ ((noinline)); static inline void inlined_wrong (TEntry *entry_p, int flag); void inlined_wrong (TEntry *entry_p, int flag) { unsigned char index; entry_p->num = 0; if (!flag) fake_assert (0); for (index = 0; index < 1; index++) entry_p->num++; asm ("before"); if (entry_p->num) { fake_assert(0); asm ("#here"); } } void expect_func (int a, unsigned char *b) { if (fake_expect ((a == 0), 0)) fake_assert (0); if (fake_expect ((b == 0), 0)) fake_assert (0); } void broken () { unsigned char index = 0; TTable *table_p = init(); inlined_wrong (&(table_p->data[1]), 1); expect_func (0, &index); inlined_wrong ((TEntry *)0xf00f, 1); LocalFreeMemory (&table_p); } we get after FRE: broken () { unsigned char index; unsigned char D.1321; unsigned char D.1320; unsigned char index; unsigned char D.1316; unsigned char D.1315; struct TTable * table_p; unsigned char index; struct TEntry * D.1281; struct TTable * table_p.1; struct TTable * table_p.0; <bb 2>: index = 0; table_p.0_1 = init (); table_p = table_p.0_1; table_p.1_2 = table_p.0_1; D.1281_3 = &table_p.1_2->data[1]; table_p.1_2->data[1].num = 0; goto <bb 4>; <bb 3>: D.1315_4 = D.1281_3->num; D.1316_5 = D.1315_4 + 1; D.1281_3->num = D.1316_5; index_7 = index_6 + 1; <bb 4>: # index_6 = PHI <0(2), index_7(3)> if (index_6 == 0) goto <bb 3>; else goto <bb 5>; <bb 5>: __asm__ __volatile__("before"); D.1315_8 = 0; expect_func (0, &index); 61455B->num ={v} 0; goto <bb 7>; <bb 6>: D.1320_10 ={v} 61455B->num; D.1321_11 = D.1320_10 + 1; 61455B->num ={v} D.1321_11; index_13 = index_12 + 1; <bb 7>: # index_12 = PHI <0(5), index_13(6)> if (index_12 == 0) goto <bb 6>; else goto <bb 8>; <bb 8>: __asm__ __volatile__("before"); D.1320_14 ={v} 61455B->num; if (D.1320_14 != 0) goto <bb 9>; else goto <bb 10>; <bb 9>: fake_assert (0); __asm__ __volatile__("#here"); <bb 10>: LocalFreeMemory (&table_p); return; } Note the check "if (entry_p->num)" and associated block is completely eliminated. The dumps indicate: Replaced table_p with table_p.0_1 in table_p.1_2 = table_p; Replaced table_p.1_2->data[1].num with 0 in D.1315_8 = table_p.1_2->data[1].num; Removing basic block 6 ;; basic block 6, loop depth 0, count 0 ;; prev block 5, next block 7 ;; pred: 5 [39.0%] (true,exec) ;; succ: 7 [100.0%] (fallthru,exec) <bb 6>: fake_assert (0); __asm__ __volatile__("#here"); If the same code is compiled with the function "inlined_wrong" declared as static inline void inlined_wrong (TEntry *entry_p, int flag) __attribute__ ((always_inline)); The generated code is correct with the check in place, suggesting ipa-inline is troublesome while early inlining works okay? -- Summary: FRE optimizes away valid code after IPA inlining Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rahul at icerasemi dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42614
next reply other threads:[~2010-01-04 18:24 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-01-04 18:24 rahul at icerasemi dot com [this message] 2010-01-04 19:34 ` [Bug tree-optimization/42614] " rguenth at gcc dot gnu dot org 2010-01-05 11:14 ` stubbs at icerasemi dot com 2010-01-05 11:31 ` rahul at icerasemi dot com 2010-01-05 11:31 ` [Bug tree-optimization/42614] [4.4 Regression] " rguenth at gcc dot gnu dot org 2010-01-05 11:39 ` rguenth at gcc dot gnu dot org 2010-01-05 11:42 ` stubbs at icerasemi dot com 2010-01-05 11:57 ` rguenth at gcc dot gnu dot org 2010-01-05 11:58 ` rguenth at gcc dot gnu dot org 2010-01-05 12:17 ` rguenth at gcc dot gnu dot org 2010-01-05 12:20 ` rguenth at gcc dot gnu dot org 2010-01-05 12:23 ` stubbs at icerasemi dot com 2010-01-05 12:32 ` stubbs at icerasemi dot com 2010-01-05 13:42 ` rguenth at gcc dot gnu dot org 2010-01-05 13:43 ` rguenth at gcc dot gnu dot org 2010-01-05 13:43 ` rguenth at gcc dot gnu dot org 2010-01-19 10:39 ` rguenth 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=bug-42614-17160@http.gcc.gnu.org/bugzilla/ \ --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).