<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div></div><div><br></div><div>It looks like edge weights aren't handled correctly when there are duplicate entries for a basic block in the successor list.</div><div><br></div><div>This is the quadratic loop:</div><div><br></div><div><div>  for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),</div><div>       E = MBB->succ_end(); I != E; ++I) {</div><div>    uint32_t Weight = getEdgeWeight(MBB, *I);</div><div>    Sum += Weight;</div><div>  }</div><div><br></div><div>The getEdgeWeight(Src, Dst) function does a linear search: std::find(Src->succ_begin(), Src->succ_end(), Dst), making the loop quadratic in MBB->succ_size().</div><div><br></div><div>MachineBasicBlock can have duplicate successor entries:</div><div><br></div><div>  MBB->addSuccessor(Succ, 10)</div><div><div>  MBB->addSuccessor(Succ, 20)</div><div><br></div><div>We don't merge these weights, instead getEdgeWeight just returns the first weight added:</div><div><br></div><div>  getEdgeWeight(MBB, Succ) -> 10</div><div><br></div><div>My patch changes the computed sum from 10+10 to the correct 10+20. This triggered assertions because other code assumes there are no duplicate edges when calling getEdgeWeight().</div><div><br></div><div>IMHO, we shouldn't allow duplicate CFG edges at all.</div><div><br></div><div>/jakob</div><div><br></div></div></div></div></body></html>