[Bug target/112760] [14 Regression] wrong code with -O2 -fno-dce -fno-guess-branch-probability -m8bit-idiv -mavx --param=max-cse-insns=0 and __builtin_add_overflow_p()
zsojka at seznam dot cz
gcc-bugzilla@gcc.gnu.org
Wed Nov 29 08:02:48 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112760
--- Comment #1 from Zdenek Sojka <zsojka at seznam dot cz> ---
Created attachment 56716
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56716&action=edit
more complex testcase, with less compiler flags
Attached a testcase that needs only -O2 -mavx; might be a different issue,
though.
$ x86_64-pc-linux-gnu-gcc -m32 -O2 -mavx testcase.c
$ ./a.out
Aborted
$ diff -u a-testcase.GOOD.s a-testcase.BAD.s
--- a-testcase.GOOD.s 2023-11-29 08:53:43.058791568 +0100
+++ a-testcase.BAD.s 2023-11-29 08:52:39.878792460 +0100
@@ -4,7 +4,7 @@
# compiled by GNU C version 14.0.0 20231128 (experimental), GMP version
6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP
# GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
-# options passed: -m32 -masm=intel -mtune=generic -march=x86-64 -O2
+# options passed: -m32 -mavx -masm=intel -mtune=generic -march=x86-64 -O2
.text
.p2align 4
.globl foo0
@@ -37,19 +37,19 @@
rol ax, 8 # _5,
# testcase.c:11: u64 u64_1 = __builtin_bswap16 (SHL (u64_0, u8_0)) % u16_0;
div bx # u16_0
-# testcase.c:12: u8 u8_1 = __builtin_add_overflow_p (u8_0, u8_0, u8_0);
- mov eax, ecx # u8_0, u8_0
# testcase.c:13: u32 u32_1 = foo0_u32_0 & u16_0;
movzx ebx, bx # u16_0, u16_0
# testcase.c:12: u8 u8_1 = __builtin_add_overflow_p (u8_0, u8_0, u8_0);
- add al, cl # u8_0, u8_0
+ add al, al # u8_0, u8_0
+# testcase.c:14: u32 u32_2 = __builtin_sub_overflow_p (0, u64_1, (u8) 0);
+ movzx edx, dx # _6, tmp127
+# testcase.c:12: u8 u8_1 = __builtin_add_overflow_p (u8_0, u8_0, u8_0);
setc al #, _15
# testcase.c:14: u32 u32_2 = __builtin_sub_overflow_p (0, u64_1, (u8) 0);
xor ecx, ecx # tmp133
# testcase.c:13: u32 u32_1 = foo0_u32_0 & u16_0;
and ebx, DWORD PTR foo0_u32_0 # u32_1, foo0_u32_0
# testcase.c:14: u32 u32_2 = __builtin_sub_overflow_p (0, u64_1, (u8) 0);
- movzx edx, dx # _6, tmp127
sub ecx, edx # tmp132, _6
setb dl #, _18
and ecx, -256 # tmp132,
Here, the problem is with:
# testcase.c:12: u8 u8_1 = __builtin_add_overflow_p (u8_0, u8_0, u8_0);
add al, al # u8_0, u8_0
due to the:
-# testcase.c:12: u8 u8_1 = __builtin_add_overflow_p (u8_0, u8_0, u8_0);
- mov eax, ecx # u8_0, u8_0
there is no "u8_0" in eax
Maybe the compiler tries to use an AVX instruction, that is in the end not
generated?
More information about the Gcc-bugs
mailing list