https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95382
Bug ID: 95382 Summary: [haifa-sched][DO_PREDICATION] execution test: wrong scheduling result. Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xuemaosheng at huawei dot com Target Milestone: --- Created attachment 48626 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48626&action=edit the source file After we enable the schedule DO_PREDICATION, we get wrong scheduling result in sched2 pass. The key dump is shown as following: .......(Unimportant things) ;; | 93 | 15 | a20=sxn([a19]) ;; | 94 | 10 | t2=a20==0 ;; | 95 | 9 | pc={(t2!=0)?L107:pc} jump_insn1 ;; | 159 | 10 | a21=0xffffffffffff8000 ;; | 98 | 9 | t0=a23!=a21 ;; | 99 | 8 | pc={(t0==0)?L173:pc} jump_insn2 ;; | 105 | 7 | a22=a23/a20 div_insn ;; | 106 | 1 | a23=sxn(a22) .......(Unimportant things) ;; --- EBB Dependences --- from bb4 to bb6 ;; insn code bb dep prio cost reservation .......(Unimportant things) ;; 93 94 4 4 15 1 : 105(t,1) 99(a,0) 94(t,5) ;; 94 1645 4 1 10 1 : 106(t,1) 95(t,1) ;; 95 139 4 13 9 1 : 106(c,1) 99(a,1)nm ;; 159 129 5 0 10 1 : 98(t,1) ;; 98 1650 5 2 9 1 : 105(t,1) 106(t,1)m 99(t,1) ;; 99 139 5 15 8 1 : 105(c,1) 106(c,1) ;; 105 37 6 4 7 1 : 106(t,6)m ;; 106 94 6 6 1 1 : .......(Unimportant things) When we enable the schedule DO_PREDICATION, we can produce conditional execution insn. Since insn 98(t0=a23!=a21) doesn't have dependence with jump_insn1 95 (pc={(t2!=0)?L107:pc}), so insn 98 can issue before jump_insn1 95. And insn 93 (a20=sxn([a19])) can also issue before jump_insn1 95. After that, insn 105(a22=a23/a20) can become conditional execution insn shown as following dump: ;; 51--> 93 a20=sxn([a19]) : rescanning insn with uid = 105. ;; dependencies resolved: insn 105 predicated ;; Ready-->Q: insn 105: queued for 1 cycles (change queue index). ;; tick updated: insn 105 into queue with cost=1 After predicating, insn 105 have become : [t0]a22=a23/a20 ;; 52--> 105 (t0) a22=a23/a20 : ;; Ready list (t = 52): .......(Unimportant things) ;; Ready list (t = 56): 94:50:prio=10 [52;56]:94 ;; 56--> 94 t2=a20==0 : .......(Unimportant things) ;; Ready list (t = 57): 95:51:prio=9 [56;57]:95 ;; 57--> 95 pc={(t2!=0)?L107:pc} : finally, insn 105([t0]a22=a23/a20) is issued before insn 95 (pc={(t2!=0)?L107:pc}). However, insn 95 has decided reg a20 is valid not. In this case, a20 is 0, so we get division by 0 error. The scheduling result is shown as the following: tstneq@ags t0, a23, a21 # [28] # 98 .... l16si@agl a20, a19, 0 # [51] # 93 .... [t0] quos@sau a22, a23, a20 # [52] # 105 tsteqi@sau t2, a20, 0 # [53] # 94 [t2] b@pcu .L5, 1 # [54] # 95 [!t0] b@pcu .L28, 0 # [55] # 99 ...... Insn 105 (div_insn)should not be issued before insn 95(jump_insn1). Note: This ebb is 3 basic-blocks. Since supporting DO_PREDICATION target is little, it's difficult to recurrent in other target. How can we solve the problem?