public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wschmidt at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/56605] New: Redundant branch introduced during loop2 phases
Date: Tue, 12 Mar 2013 18:57:00 -0000	[thread overview]
Message-ID: <bug-56605-4@http.gcc.gnu.org/bugzilla/> (raw)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56605

             Bug #: 56605
           Summary: Redundant branch introduced during loop2 phases
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: wschmidt@gcc.gnu.org
                CC: bergner@vnet.ibm.com
              Host: powerpc64-unknown-linux-gnu
            Target: powerpc64-unknown-linux-gnu
             Build: powerpc64-unknown-linux-gnu


I've recently noticed that GCC commonly generates redundant branches prior to
vectorized loops, such as:

   cmpwi 7,12,0
    ...
   beq- 7,.L22
   beq- 7,.L22
   .p2align 4,,15
.L8:
    ... loop body ...

The branches first appear in the 186r.loop2_doloop debug dump:

(note 260 254 258 23 [bb 23] NOTE_INSN_BASIC_BLOCK)
(insn 258 260 259 23 (set (reg:CC 330)
        (compare:CC (subreg:SI (reg:DI 153 [ bnd.10+-4 ]) 4)
            (const_int 0 [0]))) -1
     (nil))
(jump_insn 259 258 263 23 (set (pc)
        (if_then_else (eq (reg:CC 330)
                (const_int 0 [0]))
            (label_ref 257)
            (pc))) -1
     (expr_list:REG_BR_PROB (const_int 0 [0])
        (nil))
 -> 257)
(note 263 259 261 24 [bb 24] NOTE_INSN_BASIC_BLOCK)
(insn 261 263 262 24 (set (reg:CC 331)
        (compare:CC (subreg:SI (reg:DI 153 [ bnd.10+-4 ]) 4)
            (const_int 0 [0]))) -1
     (nil))
(jump_insn 262 261 257 24 (set (pc)
        (if_then_else (eq (reg:CC 331)
                (const_int 0 [0]))
            (label_ref 257)
            (pc))) -1
     (expr_list:REG_BR_PROB (const_int 0 [0])
        (nil))
 -> 257)

Subsequently GCC removes the redundant compare, but does not remove the
redundant branch.

Simple test case to reproduce:

#define N 4000
void foo(short* __restrict sb, int* __restrict ia) {
  int i;
  for (i = 0; i < N; i++)
    ia[i] = (int) sb[i];
}

$GCC_INSTALL/bin/gcc -S -O3 -mvsx example.c

(-mvsx is necessary to vectorize the loop.  It may also be necessary to add
-mcpu=power7.)


             reply	other threads:[~2013-03-12 18:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12 18:57 wschmidt at gcc dot gnu.org [this message]
2013-03-12 19:20 ` [Bug rtl-optimization/56605] " steven at gcc dot gnu.org
2013-03-12 19:54 ` steven at gcc dot gnu.org
2013-03-12 23:00 ` steven at gcc dot gnu.org
2013-03-12 23:15 ` steven at gcc dot gnu.org
2013-04-15 18:32 ` wschmidt at gcc dot gnu.org
2013-04-23 19:49 ` wschmidt 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-56605-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: link
Be 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).