https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118467
Bug ID: 118467 Summary: Missed pointer overflow optimisation Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: sjames at gcc dot gnu.org Target Milestone: --- Created attachment 60148 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60148&action=edit mbrtowc.c.xz This comes from https://inbox.sourceware.org/libc-alpha/20250114014804.79188-1-yunqi...@isrc.iscas.ac.cn/T/#u which is the same as PR82694. ``` $ gcc mbrtowc.c -std=gnu11 -fgnu89-inline -O2 -fPIE -ftls-model=initial-exec -fmerge-all-constants -frounding-math -fno-stack-protector -fmath-errno -c -ggdb3 [...] $ objdump -S mbrtowc.o [...] inbuf = (const unsigned char *)s; endbuf = inbuf + n; if (__builtin_expect((endbuf < inbuf), 0)) { 7d: 48 01 d8 add %rbx,%rax inbuf = (const unsigned char *)s; 80: 48 89 5c 24 28 mov %rbx,0x28(%rsp) if (__builtin_expect((endbuf < inbuf), 0)) { 85: 4c 8d 4c 24 20 lea 0x20(%rsp),%r9 8a: 48 89 c1 mov %rax,%rcx 8d: 0f 82 a5 00 00 00 jb 138 <__mbrtowc+0x138> endbuf = (const unsigned char *)~(uintptr_t)0; if (endbuf == inbuf) ``` We don't seem to optimise the comparison of endbuf/inbuf away.