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: unassig...@gcc.gnu.org

        ReportedBy: wschm...@gcc.gnu.org

                CC: berg...@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 via email to