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

            Bug ID: 126118
           Summary: [SH] Redundant movt tst sequence
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
  Target Milestone: ---

Compiling the following with -m4-single -O2


_Bool is_eof(unsigned int val) {
    unsigned int zero = 0;
    register unsigned int t asm("t");

    __asm__ __inline__("cmp/str %[zero],%[val]" :: [zero]"r"(zero),
[val]"r"(val) : "t");

    return t;
}


results in:
_is_eof:
        mov     #0,r1     ! 10      [c=4 l=2]  movsi_ie/2
! 6 "/app/example.c" 1
        cmp/str r1,r4
! 0 "" 2
        movt    r1          ! 13    [c=4 l=2]  movt
        tst     r1,r1     ! 14      [c=4 l=2]  cmpeqsi_t/0
        mov     #-1,r0    ! 15    [c=4 l=2]  movsi_ie/2
        rts           ! 36    [c=0 l=2]  *return_i
        negc    r0,r0   ! 16  [c=0 l=2]  movrt_negc


while up to GCC 15 it produced:
_is_eof:
        mov     #0,r1     ! 10      [c=4 l=2]  movsi_ie/2
! 6 "/app/example.c" 1
        cmp/str r1,r4
! 0 "" 2
        rts           ! 36    [c=0 l=2]  *return_i
        movt    r0          ! 27    [c=4 l=2]  movt

Reply via email to