https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78579
Bug ID: 78579 Summary: redundant instruction of the form cmp r0, r0 generated in assembly with -O2 Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: prathamesh3492 at gcc dot gnu.org Target Milestone: --- Hi, While investigating PR78529, I came across the following issue: For the test-case: char *f(char *dest, char *src) { if (__builtin_strcpy (dest + 5, src) != (dest + 5)) __builtin_abort (); } gcc -O2 generates following assembly: f: .LFB0: .cfi_startproc leaq 5(%rdi), %rdx subq $8, %rsp .cfi_def_cfa_offset 16 movq %rdx, %rdi call strcpy cmpq %rax, %rax jne .L5 addq $8, %rsp .cfi_remember_state .cfi_def_cfa_offset 8 ret .L5: .cfi_restore_state call abort .cfi_endproc This seems to start after "pro_and_epligoue" pass, which contains the following insn in it's dump: (insn 14 29 15 2 (set (reg:CCZ 17 flags) (compare:CCZ (reg/f:DI 0 ax [orig:87 _1 ] [87]) (reg:DI 0 ax [92]))) "strcpy-foo.c":3 8 {*cmpdi_1} (nil)) full dump: http://pastebin.com/TGMRFGyw Thanks, Prathamesh