[Bug target/124993] Inefficient return of short struct with 3 or more members

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 23 05:53:26 GMT 2026


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2026-04-23
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Code is going to be ugly, but of course the code as is suffers from STLF fails.
 I suppose even a movb $dl, $dih would be faster than that ...

typedef struct triplet { char a, b, c; } triplet;
triplet tconst(char a, char b, char c) {
    return (triplet){a, b, c};
}

also shows this main issue:

tconst:
.LFB0:
        .cfi_startproc
        movb    %dil, -4(%rsp)
        movzbl  %dl, %edx
        movb    %sil, -3(%rsp)
        movzwl  -4(%rsp), %eax
        salq    $16, %rdx
        orl     %edx, %eax
        ret

we are expanding from

  D.2970.a = a_2(D);
  D.2970.b = b_4(D);
  D.2970.c = c_6(D);
  return D.2970;

and combining this with the return dance we emit for return D.2970 this
becomes unwieldly:

    5: NOTE_INSN_FUNCTION_BEG
    8: [r93:DI-0x4]=r99:QI
    9: [r93:DI-0x3]=r100:QI
   10: [r93:DI-0x2]=r101:QI
   11: r102:DI=0
   12: r103:DI=zero_extend([r93:DI-0x4])
   13: r104:DI=zero_extend(r103:DI#0)
   14: {r105:DI=r102:DI&0xffffffffffff0000;clobber flags:CC;}
   15: {r106:DI=r105:DI|r104:DI;clobber flags:CC;}
   16: r102:DI=r106:DI
   17: r107:DI=zero_extend([r93:DI-0x2])
   18: r108:DI=zero_extend(r107:DI#0)
   19: {r109:DI=r108:DI<<0x10;clobber flags:CC;}
   20: {r110:DI=r102:DI&0xffffffffff00ffff;clobber flags:CC;}
   21: {r111:DI=r110:DI|r109:DI;clobber flags:CC;}
   22: r102:DI=r111:DI 
   23: r112:DI=r102:DI
   24: r98:SI=r112:DI#0
   28: ax:SI=r98:SI
   29: use ax:SI

I suppose extending D.2970 with padding would allow a simple SImode load
(still STLF fail in that case).


More information about the Gcc-bugs mailing list