https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129169
Bug ID: 129169
Summary: [14/15/16/17 Regression] wrong code at -O2 with
(__int128) x * INT64_MIN >> 63 for x in [0, 63]
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: jeffchen006 at gmail dot com
Target Milestone: ---
$ cat t.c
#include <stdint.h>
#include <stdio.h>
__attribute__((noipa)) uint8_t f(unsigned c) {
c &= 63;
return c * (__int128) INT64_MIN >> 63;
}
int main() { printf("%d\n", f(8)); }
$ gcc -O0 t.c -lm && ./a.out
248
$ gcc -O2 t.c -lm && ./a.out
8
Trunk (r17-5981-g78124a426ab, x86_64-pc-linux-gnu): wrong at -Os, -O2, -O3;
-O0, -O1 correct.
Releases: 10.5: -O2 ok, -O3 ok; 12.5: -O2 ok, -O3 ok; 13.4: -O2 ok, -O3 ok;
14.3: -O2 wrong, -O3 wrong; 15.2: -O2 wrong, -O3 wrong; 16.2: -O2 wrong, -O3
wrong.
Each of these makes it go away at -O3: -fdisable-rtl-combine
-fdisable-tree-widening_mul.
Started with r14-8680-g2f14c0dbb78985 ("PR target/113560: Enhance
is_widening_mult_rhs_p."); bisected on the unreduced test with -O3
-march=x86-64-v3 -fwrapv.
-fsanitize=undefined,address is clean at -O0; -ftrivial-auto-var-init=pattern
does not change the -O0 output.