https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64331
Bug ID: 64331 Summary: regcprop propagates registers noted as REG_DEAD Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: senthil_kumar.selvaraj at atmel dot com Created attachment 34290 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34290&action=edit Source file For the AVR target, compiling the attached source file with -O1 results in code like this <snip> or r20,r21 or r20,r22 or r20,r23 breq .L1 ldd r24,Z+4 ldd r25,Z+5 ldd r26,Z+6 ldd r27,Z+7 cp r20,r24 cpc r21,r25 cpc r22,r26 cpc r23,r27 </snip> Register R20 was clobbered first up, but is used to compare against R24. fdump-rtl-all-raw showed that cprop_hardreg is the culprit. In pass *.ce3 <snip> (insn 7 4 8 2 (set (reg:SI 16 r16 [orig:43 D.1617 ] [43]) (reg/v:SI 20 r20 [orig:46 x ] [46])) reduced.c:12 94 {*movsi} (nil)) ... (insn 13 12 14 3 (parallel [ (set (cc0) (compare (reg/v:SI 20 r20 [orig:46 x ] [46]) (const_int 0 [0]))) (clobber (scratch:QI)) ]) reduced.c:17 413 {*cmpsi} (expr_list:REG_DEAD (reg/v:SI 20 r20 [orig:46 x ] [46]) (nil))) ... (insn 17 16 18 4 (parallel [ (set (cc0) (compare (reg:SI 16 r16 [orig:43 D.1617 ] [43]) (reg:SI 24 r24 [orig:48 t_3(D)->b ] [48]))) (clobber (scratch:QI)) ]) reduced.c:20 413 {*cmpsi} (expr_list:REG_DEAD (reg:SI 24 r24 [orig:48 t_3(D)->b ] [48]) (expr_list:REG_DEAD (reg:SI 16 r16 [orig:43 D.1617 ] [43]) (nil)))) </snip> into <snip> ;; Function foo (foo, funcdef_no=0, decl_uid=1599, cgraph_uid=0, symbol_order=0) insn 17: replaced reg 16 with 20 rescanning insn with uid = 17. .. (insn 17 16 18 4 (parallel [ (set (cc0) (compare (reg:SI 20 r20 [orig:43 D.1617 ] [43]) (reg:SI 24 r24 [orig:48 t_3(D)->b ] [48]))) (clobber (scratch:QI)) ]) reduced.c:20 413 {*cmpsi} (expr_list:REG_DEAD (reg:SI 24 r24 [orig:48 t_3(D)->b ] [48]) (expr_list:REG_DEAD (reg:SI 16 r16 [orig:43 D.1617 ] [43]) (nil)))) </snip> The AVR backend, on seeing that reg:SI r20 is dead in insn 13, emits code that clobbers r20, and this breaks the read in insn 17.