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

            Bug ID: 123656
           Summary: [16 Regression] wrong code with unsigned char [2]
                    vector multiplication by 210 at -Og
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Created attachment 63373
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63373&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc -Og testcase.c
$ ./a.out 
Aborted                    ./a.out


At the ASM level, the multiplication by 210 seems to be done as n*7*15*2:

"foo":
.LFB0:
        .cfi_startproc
        mov     edx, edi        # v, v
# testcase.c:6:   return v * 210;
        mov     eax, edi        # _4, v
        sal     ah, 3   # _4,
        sal     al, 3   # _4,
        sub     al, dil # _5, v
        sub     ah, dh  # _5, v
        mov     edx, eax        # _6, _5
        sal     dh, 4   # _6,
        sal     dl, 4   # _6,
        sub     al, dl  # _7, _6
        sub     ah, dh  # _7, _6
        add     ah, ah  # _8
        add     al, al  # _8
# testcase.c:7: }
        ret     

but the multiplication by 15 seems to multiply by -15 instead.

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-20260118011631-r16-6881-gddda478641ffcc-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/16.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--disable-bootstrap --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --enable-libsanitizer
--disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-20260118011631-r16-6881-gddda478641ffcc-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.1 20260118 (experimental) (GCC)

Reply via email to