<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks for reverting Dave. Sorry for the breakage. This should be enough information for me to revise the patch & add a regression test.<div class=""><br class=""></div><div class="">vedant<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 27, 2018, at 5:56 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Looks like this is causing a crash - the pass later assumes that all the select instructions discovered are contiguous.<br class=""><br class="">This resulted in a crash later in CodeGenPrep because the last instruction in the BB wasn't actually a terminator. A basic block ends like this (where the select had been replaced by the branch, but then the llvm.dbg.value was left after that select/br):<br class=""><br class=""><div class="">    br i1 %495, label ..., label ..., !dbg !251, !prof !252</div><div class="">    call void @llvm.dbg.value(metadata float ..., metadata !152, metadata !DIExpression()), !dbg !241<br class=""><br class="">(specifically, the backtrace is:<br class=""><br class=""><div class="">llvm::dyn_cast<llvm::ReturnInst, llvm::TerminatorInst> (Val=0x0) at include/llvm/Support/Casting.h:334</div><div class="">CodeGenPrepare::dupRetToEnableTailCallOpts (...) at lib/CodeGen/CodeGenPrepare.cpp:1794</div><div class="">CodeGenPrepare::optimizeBlock (... at lib/CodeGen/CodeGenPrepare.cpp:6703</div><div class="">CodeGenPrepare::runOnFunction (...) at lib/CodeGen/CodeGenPrepare.cpp:447<br class=""><br class="">(the dyn_cast is passed zero because getTerminator() on the BB returns null - because of the fact that it doesn't end with a terminator)</div><br class="">I'm going to revert this for now - do you think you'd need a test case from me to reproduce this failure? I can try to reduce something from the internal code that triggered this, but might take a bit of work - happy to do so if you need it but I'm hoping the rough explanation will suffice to get you to something useful faster than I can, given you've been poking around in the code already recently.<br class=""><br class="">Reverted in r340794<br class=""><br class="">- Dave</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Aug 21, 2018 at 4:43 PM Vedant Kumar via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: vedantk<br class="">
Date: Tue Aug 21 16:42:38 2018<br class="">
New Revision: 340368<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=340368&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=340368&view=rev</a><br class="">
Log:<br class="">
[CodeGenPrepare] Scan past debug intrinsics to find select candidates (NFC)<br class="">
<br class="">
In optimizeSelectInst, when scanning for candidate selects to rewrite<br class="">
into branches, scan past debug intrinsics. This makes the debug-enabled<br class="">
and non-debug paths through optimizeSelectInst more congruent.<br class="">
<br class="">
NFC because every select is eventually visited either way.<br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br class="">
<br class="">
Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=340368&r1=340367&r2=340368&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=340368&r1=340367&r2=340368&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)<br class="">
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Aug 21 16:42:38 2018<br class="">
@@ -5599,9 +5599,10 @@ bool CodeGenPrepare::optimizeSelectInst(<br class="">
   // Find all consecutive select instructions that share the same condition.<br class="">
   SmallVector<SelectInst *, 2> ASI;<br class="">
   ASI.push_back(SI);<br class="">
-  for (BasicBlock::iterator It = ++BasicBlock::iterator(SI);<br class="">
-       It != SI->getParent()->end(); ++It) {<br class="">
-    SelectInst *I = dyn_cast<SelectInst>(&*It);<br class="">
+  for (Instruction *NextInst = SI->getNextNonDebugInstruction();<br class="">
+       NextInst != SI->getParent()->getTerminator();<br class="">
+       NextInst = NextInst->getNextNonDebugInstruction()) {<br class="">
+    SelectInst *I = dyn_cast<SelectInst>(NextInst);<br class="">
     if (I && SI->getCondition() == I->getCondition()) {<br class="">
       ASI.push_back(I);<br class="">
     } else {<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div></div>
</div></blockquote></div><br class=""></div></body></html>