https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95447
Bug ID: 95447 Summary: cmpstrn peepholes are out of date Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: crazylht at gmail dot com, hubicka at ucw dot cz, ubizjak at gmail dot com Target Milestone: --- Target: i386,x86-64 cmpstrn peepholes are out of date. i386.md has ;; Peephole optimizations to clean up after cmpstrn*. This should be ;; handled in combine, but it is not currently up to the task. ;; When used for their truth value, the cmpstrn* expanders generate ;; code like this: ;; ;; repz cmpsb ;; seta %al ;; setb %dl ;; cmpb %al, %dl ;; jcc label ;; ;; The intermediate three instructions are unnecessary. But GCC no longer generates such code sequence. Instead, we generate [hjl@gnu-cfl-2 pr95151]$ cat s1.i extern void bar (void); void func (char *d, unsigned int l) { if (__builtin_strncmp (d, "foo", l)) bar (); } [hjl@gnu-cfl-2 pr95151]$ gcc -O2 -minline-all-stringops -S s1.i [hjl@gnu-cfl-2 pr95151]$ cat s1.s .file "s1.i" .text .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "foo" .text .p2align 4 .globl func .type func, @function func: .LFB0: .cfi_startproc cmpl $4, %esi movl %esi, %ecx movl $4, %eax movq %rdi, %r8 cmova %rax, %rcx movl $.LC0, %edi movq %r8, %rsi cmpq %rcx, %rcx repz cmpsb seta %al sbbb $0, %al testb %al, %al jne .L4 ret .p2align 4,,10 .p2align 3 .L4: jmp bar .cfi_endproc .LFE0: .size func, .-func .ident "GCC: (GNU) 10.1.1 20200507 (Red Hat 10.1.1-1)" .section .note.GNU-stack,"",@progbits [hjl@gnu-cfl-2 pr95151]$ The cmpstrn peepholes never kick in.