https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60406

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
It looks that a hack, mentioned in Comment #0 should use asm goto instead of
goto. The following test:

--cut here--
extern void foo (void *);

int test_bad (int p1, int p2)
{
  __label__ bla1;

  foo (&&bla1);
  goto bla1;
 bla1:
  return 0;
}

int test_good (int p1, int p2)
{
  __label__ bla2;

  foo (&&bla2);
  asm goto ("" :::: bla2);
 bla2:
  return 0;
}
--cut here--

results in (-O2):

test_good:
        subl    $28, %esp
        movl    $.L5, (%esp)
        call    foo
.L6:
.L5:
        xorl    %eax, %eax
        addl    $28, %esp
        ret

which is much better than:

test_bad:
.L2:
        subl    $28, %esp
        movl    $.L2, (%esp)
        call    foo
        xorl    %eax, %eax
        addl    $28, %esp
        ret

Also checked on alpha:

test_good:
        .frame $30,16,$26,0
        .mask 0x4000000,-16
$LFB1:
        .cfi_startproc
        ldah $29,0($27)         !gpdisp!4
        lda $29,0($29)          !gpdisp!4
$test_good..ng:
        lda $30,-16($30)
        .cfi_def_cfa_offset 16
        cpys $f31,$f31,$f31
        ldah $16,$L4($29)               !gprelhigh
        ldq $27,foo($29)                !literal!5
        stq $26,0($30)
        .cfi_offset 26, -16
        .prologue 1
        lda $16,$L4($16)                !gprellow
        jsr $26,($27),foo               !lituse_jsr!5
        ldah $29,0($26)         !gpdisp!6
        lda $29,0($29)          !gpdisp!6
        .align 3 #realign
$L5:
$L4:
        mov $31,$0
        ldq $26,0($30)
        lda $30,16($30)
        .cfi_restore 26
        .cfi_def_cfa_offset 0
        ret $31,($26),1

Please note, that the check will still need some tolerance due to various label
alignment requirements, additional instructions, etc:

  5c:   00 00 10 22     lda     a0,0(a0)
                        5c: GPRELLOW    .text+0x70              <- label loc
  60:   00 40 5b 6b     jsr     ra,(t12),64 <test_good+0x24>
                        60: LITUSE      .text+0x3
                        60: HINT        foo
  64:   00 00 ba 27     ldah    gp,0(ra)                        <- retaddr
                        64: GPDISP      .text+0x4
  68:   00 00 bd 23     lda     gp,0(gp)
  6c:   00 00 fe 2f     unop
  70:   00 04 ff 47     clr     v0

Reply via email to