<div dir="ltr">I did a fast research into the LLVM base code and seems like, even if having multiple incoming edges for the same block is forbidden by the verifier through a check at line Verifier.cpp:1146, it is a common place assumption in SimplifyCFG that if a block branches to the same target multiple times the PHI should have multiple incoming edges from the same block.<div><br></div><div>I find this pretty strange ... I tried to remove the source of double incoming edges for the specific case in the example posted by Joerg, but doing so breaks other code that EXPECTS multiple incoming edges for the same block in certain conditions (like a conditional branch targeting the same block two times with both the True and False branches).</div><div><br></div><div>If this is the direction we want to go (continuing to support multiple incoming edges from the same block) tomorrow I will post a patch for switch to select that takes into consideration this when multiple cases of a switch target the same block and I will add Hans and Jin as reviewers.</div><div><br></div><div>Cheers,</div><div>Marcello<br><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-10-12 14:40 GMT-07:00 Marcello Maggioni <span dir="ltr"><<a href="mailto:hayarms@gmail.com" target="_blank">hayarms@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hmm,<div><br></div><div>compiling your test I've noticed that even before entering the SwitchToSelect optimization the PHI that breaks the module already has two incoming edges for the same predecessor:</div><div><br></div><div>This is the IR just entering SwitchToSelect:</div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">; Function Attrs: nounwind ssp uwtable</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">define i32 @fn1() #0 {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">entry:</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  %0 = load i32* @b, align 4</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  %tobool = icmp eq i32 %0, 0</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  br i1 %tobool, label %if.end3, label %if.then</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40);min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">if.then:                                          ; preds = %entry</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  %1 = load i32* @a, align 4</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  switch i32 %1, label %if.end3 [</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">    i32 5, label %return</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">    i32 0, label %return</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  ]</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40);min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">if.end3:                                          ; preds = %if.then, %entry</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  br label %return</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40);min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">return:                                           ; preds = %if.then, %if.then, %if.end3</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  %retval.0 = phi i32 [ 0, %if.end3 ], [ %1, %if.then ], [ %1, %if.then ]</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">  ret i32 %retval.0</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(215,201,167);background-color:rgb(142,53,40)">}</p></div><div><br></div><div>Is this condition expected to be handled by the switch lowering? Or is the switch formation that probably introduced this malformed?</div><div>Is pretty easily to workaround this in SwitchToSelect to reiterate Incoming Edge deletion when the switch is removed until no more edges from the same predecessor are found, but I guess if we have some other issue more up in the pipeline.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-10-12 14:35 GMT-07:00 Marcello Maggioni <span dir="ltr"><<a href="mailto:hayarms@gmail.com" target="_blank">hayarms@gmail.com</a>></span>:<div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks again Joerg, I missed the attachment!<div><br></div><div>Marcello</div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-10-12 13:50 GMT-07:00 Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>></span>:<div><div><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Sun, Oct 12, 2014 at 01:09:25PM -0700, Marcello Maggioni wrote:<br>
> Thanks Joerg for reverting and thanks Jiangning for reporting the problem.<br>
><br>
> Would it be possible to have the snippet of the code that is causing the<br>
> issue or is it not publicly available? In order to be able to debug this<br>
> more effectively and safely.<br>
<br>
</span>See my earlier post in this thread for a test case.<br>
<span><font color="#888888"><br>
Joerg<br>
</font></span></blockquote></div></div></div><br></div>
</blockquote></div></div></div><br></div>
</blockquote></div><br></div>