public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "steven at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/53804] New: branch reordering missed optimization Date: Fri, 29 Jun 2012 10:36:00 -0000 [thread overview] Message-ID: <bug-53804-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53804 Bug #: 53804 Summary: branch reordering missed optimization Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: steven@gcc.gnu.org Consider this test case: int foo1 (int a, int b) { if (a > 0) return 1; else if (b > 0 && a < 0) return -3; return 9; } int foo2 (int a, int b) { if (a > 0) return 1; else if (a < 0 && b > 0) return -3; return 9; } Ideally these two functions would be optimized to the same code, because they are semantically equivalent. The ideal form is foo2 because the result of the first comparison against "a" can be re-used for the second test, but GCC does not perform this optimization. The .227r.final dump looks like this on powerpc64-unknown-linux-gnu (all notes removed for readability): ;; Function foo1 (foo1, funcdef_no=0, decl_uid=1997, cgraph_uid=0) 11 %7:CC=cmp(%3:SI,0) # r7 = cmp(a,0) 5 %9:DI=0x1 # r9 = 1 12 pc={(%7:CC<=0)?L74:pc} # if (r7 <= 0) goto L74 L20: 26 %3:DI=%9:DI # r3 = r9 29 use %3:DI # .. 64 return # return r3 i 63: barrier L74: 14 %7:CC=cmp(%4:SI,0) # r7 = cmp (b,0) 8 %9:DI=0x9 # r9 = 9 15 pc={(%7:CC<=0)?L20:pc} # if (r7 <= 0) goto L20 53 %9:DI=-%3:DI==0 # r9 = -(r3==0) 54 {%9:DI=%9:DI&0xc;clobber scratch;} # r9 = r9 & 12 55 %9:DI=%9:DI-0x3 # r9 = r9 - 3 68 %3:DI=%9:DI # r3 = r9 69 use %3:DI # .. 70 return # return r3 i 73: barrier ;; Function foo2 (foo2, funcdef_no=1, decl_uid=2001, cgraph_uid=1) 11 %7:CC=cmp(%3:SI,0) # r7 = cmp(a,0) 12 pc={(%7:CC<=0)?L57:pc} # if (r7 <= 0) goto L57 5 %3:DI=0x1 # r3 = 1 29 use %3:DI # .. 56 return # return r3 i 55: barrier L57: 14 %7:CC=cmp(%3:DI,0) # r7 = cmp(a,0) // ??? redundant 8 %3:DI=0x9 # r3 = 9 51 use %3:DI # .. 15 pc={(%7:CC==0)?return:pc} # if (r7 == 0) return r3 17 %7:CC=cmp(%4:SI,0) # r7 = cmp(b,0) 52 use %3:DI # .. 18 pc={(%7:CC<=0)?return:pc} # if (r7 <= 0) return r3 6 %3:DI=0xfffffffffffffffd # r3 = -3 53 use %3:DI # .. 54 return # return r3 i 47: barrier Note how foo1 needs two branches whereas foo2 only needs 1. (I'm not sure why there is the redundant compare in foo2:insn 14)
next reply other threads:[~2012-06-29 10:36 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-06-29 10:36 steven at gcc dot gnu.org [this message] 2012-06-29 10:43 ` [Bug tree-optimization/53804] " steven at gcc dot gnu.org 2013-12-26 23:43 ` steven at gcc dot gnu.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-53804-4@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).