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

            Bug ID: 128885
           Summary: [16/17 Regression] wrong code at -O1/-O2: combine
                    mis-narrows truncation of a TImode logical right shift
                    ((unsigned long)(x >> 8) for unsigned __int128 x)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,

$cat repro.c

[[gnu::noipa]] unsigned __int128 f (unsigned __int128 b, unsigned long long m)
{
  return ((b >> 8) & (((unsigned __int128) 1 << 57) - 1)) * m;
}

int main (void)
{
  /* bits 8..64 of an all-ones value, times 1: 2^57 - 1.  */
  if (f (~(unsigned __int128) 0, 1) != (((unsigned __int128) 1 << 57) - 1))
    __builtin_abort ();
  return 0;
}

$ gcc -O2 repro.c && ./a.out          # also -O3, -Os;  -O0 / -O1 fine
Aborted

## Checked Versions
  - gcc 12, 13, 15.2, clang: correct; 
  - gcc 16 (r16-8100), trunk 9571dd0b721 (2026-11-17): wrong.

Reproduced in Godbolt: https://godbolt.org/z/6qMs4YeTM

Thanks.

Reply via email to