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

            Bug ID: 102205
           Summary: vec<int> + 1 could be done as vec<int> - (-1)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64

Take:
template <class T> using V [[gnu::vector_size(16)]] = T;
auto a1(V<  int> b) { return 1 + b; }

---- CUT ----
Currently GCC produces:
a1(int __vector(4)):
        paddd   .LC0(%rip), %xmm0
        ret
        .cfi_endproc
.LFE0:
        .size   a1(int __vector(4)), .-a1(int __vector(4))
        .section        .rodata.cst16,"aM",@progbits,16
        .align 16
.LC0:
        .long   1
        .long   1
        .long   1
        .long   1

----------------------------------------
But it might be best if GCC produces (like LLVM):
a1(int __vector(4)):
        pcmpeqd %xmm1, %xmm1
        psubd   %xmm1, %xmm0
        retq

Reply via email to