<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>Hi,<br><br></div>Recently, I investigated one BPF bug where a infinite looping happens<br></div>dag combine2. The test case, the bug fix and some description of the issue can be<br></div>found with the commit:<br><a href="http://reviews.llvm.org/rL249718">http://reviews.llvm.org/rL249718</a><br><br></div>The investigation of the bug does raise some interesting question about<br></div>the algorithm of dag combine2 and the usage of UNDEF sdnode, which <br></div>I want to get some feedback from the group.<br><br></div>The issue can be described by the following steps:<br><br>......<br></div><div>(1). The following node in the worklist is processed:<br>ch = store<ST2[%7+18], trunc to i16> 0x229b5a0, Constant:i64<0>, 0x2294fb8, Constant:i64<0><br></div><div>(before legalizer the last operand is undef and BPF Undef expansion legalizes it to<br></div><div> Constant:i64<0>)<br><br></div><div>(2). The following call sequence<br></div><div>      DAGCombiner::visitSTORE<br></div><div>          DAG.getTruncStore<br></div><div>               VT != SVT (i64, i16)<br></div><div>               a new StoreSDNode with ops {Chain, Val, Ptr, Undef} is created<br></div><div>          CombineTo<br></div><div>               The new StoreSDNode is added to worklist<br></div><div>               [!!! I am not sure when Undef node is added to the worklist, but<br></div><div>                    could be here]<br><br></div><div>(3). The following node in the worklist is processed:<br>ch = store<ST2[%7(align=8)+18](align=2), trunc to i16> 0x229b5a0, Constant:i64<0>, 0x2294fb8, undef:i64<br></div><div>      Its StoreSDNode->getAlignment is refined to 2, and node is not added back<br></div><div>      to the work list<br><br></div><div>(4). The following node in the worklist is processed:<br>i64 = undef<br></div><div>Legalizer actually is able to legalize it to be "i64 = Constant<0>", and<br></div><div>put both of them as updated nodes. So both of them and their users are<br></div><div>added to the worklist. One of its uses is:<br>store<ST2[%7(align=8)+18](align=2), trunc to i16> 0x229b5a0, Constant:i64<0>, 0x2294fb8, Constant:i64<0><br><br></div><div>Now we go back to (1) and the whole sequence starts again.<br></div><div><br></div><div>Any potential hole in dag combine2 algorithm esp. related with promoting Undef node?<br><br></div><div>Thanks,<br><br></div><div>Yonghong<br></div></div></div></div></div></div>