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

            Bug ID: 109249
           Summary: Missed optimization for table lookups
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Example #1 - https://godbolt.org/z/95GjPo9bs

gcc:
GetTypeDamageMultiplier(Type, Type):
        sub     rsp, 1184
        movsx   rax, edi
        movsx   rdx, esi
        mov     ecx, 162
        lea     rdi, [rsp-120]
        mov     esi, OFFSET FLAT:.LC0
        lea     rax, [rax+rax*8]
        rep     movsq
        lea     rax, [rdx+rax*2]
        movss   xmm0, DWORD PTR [rsp-120+rax*4]
        add     rsp, 1184
        ret

clang:
GetTypeDamageMultiplier(Type, Type):     # @GetTypeDamageMultiplier(Type, Type)
        movsxd  rax, edi
        lea     rax, [rax + 8*rax]
        movsxd  rcx, esi
        lea     rax, [rcx + 2*rax]
        lea     rcx, [rip + .L__const.GetTypeDamageMultiplier(Type,
Type).table]
        movss   xmm0, dword ptr [rcx + 4*rax]   # xmm0 = mem[0],zero,zero,zero
        ret

Example #2 - https://godbolt.org/z/sqocKjYco

gcc:
GetTypeDamageMultiplier(Type, Type):
        sub     rsp, 144
        movsx   rdi, edi
        movsx   rsi, esi
        movaps  xmm1, XMMWORD PTR .LC2[rip]
        movss   xmm0, DWORD PTR .LC1[rip]
        movaps  xmm2, XMMWORD PTR .LC6[rip]
        lea     rax, [rsi+rdi*8]
        movaps  XMMWORD PTR [rsp-72], xmm1
        movaps  xmm1, XMMWORD PTR .LC3[rip]
        shufps  xmm0, xmm0, 0
        movaps  XMMWORD PTR [rsp-120], xmm0
        movaps  XMMWORD PTR [rsp-104], xmm0
        movaps  XMMWORD PTR [rsp-88], xmm0
        movaps  XMMWORD PTR [rsp+8], xmm0
        movaps  xmm0, XMMWORD PTR .LC7[rip]
        movaps  XMMWORD PTR [rsp-56], xmm1
        movaps  xmm1, XMMWORD PTR .LC4[rip]
        movaps  XMMWORD PTR [rsp+24], xmm0
        movaps  xmm0, XMMWORD PTR .LC8[rip]
        movaps  XMMWORD PTR [rsp-40], xmm1
        movaps  xmm1, XMMWORD PTR .LC5[rip]
        movaps  XMMWORD PTR [rsp+40], xmm0
        movaps  xmm0, XMMWORD PTR .LC9[rip]
        movaps  XMMWORD PTR [rsp-24], xmm1
        movaps  XMMWORD PTR [rsp+56], xmm1
        movaps  xmm1, XMMWORD PTR .LC10[rip]
        movaps  XMMWORD PTR [rsp+72], xmm0
        movaps  XMMWORD PTR [rsp+104], xmm0
        movaps  xmm0, XMMWORD PTR .LC11[rip]
        movaps  XMMWORD PTR [rsp-8], xmm2
        movaps  XMMWORD PTR [rsp+88], xmm1
        movaps  XMMWORD PTR [rsp+120], xmm0
        movss   xmm0, DWORD PTR [rsp-120+rax*4]
        add     rsp, 144
        ret

clang:
GetTypeDamageMultiplier(Type, Type):     # @GetTypeDamageMultiplier(Type, Type)
        movsxd  rax, edi
        movsxd  rcx, esi
        lea     rax, [rcx + 8*rax]
        lea     rcx, [rip + .L__const.GetTypeDamageMultiplier(Type,
Type).table]
        movss   xmm0, dword ptr [rcx + 4*rax]   # xmm0 = mem[0],zero,zero,zero
        ret

Reply via email to