https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115202
Bug ID: 115202
Summary: [14/15 Regression] Missed optimization: std::min(f ?
(unsigned short)m : a, ~0)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, we noticed that the code below can be optimized to be independent of
'm', but gcc -O3 seems to have missed it.
https://godbolt.org/z/a6MoofoYK
unsigned short m;
#include <algorithm>
unsigned short func(int a, int f) {
return std::min(f ? m : a, ~0);
}
GCC-trunk -O3:
func(int, int):
movzx eax, WORD PTR m[rip]
test esi, esi
mov edx, -1
cmove eax, edi
test eax, eax
cmovns eax, edx
ret
Expected code (gcc-13.2):
func(int, int):
mov eax, edi
test edi, edi
jns .L4
test esi, esi
jne .L4
ret
.L4:
mov eax, 65535
ret
If we did it correctly, it's caused by
https://github.com/gcc-mirror/gcc/commit/7b34cacc5735385e7e2855d7c0a6fad60ef4a99b
Thank you very much for your time and effort! We look forward to hearing from
you.