<div dir="ltr">Yes, it's still respected in this case, as the only instructions that will be deleted have been RAUW with undef.<div><br><div>Originally, all instructions where RAUW but only non-EHPad were deleted (that means EHPad were RAUW but not deleted).</div><div>Then it was later patched by not RAUW token instructions and now not deleting EHPad nor token instructions.</div><div><br></div><div>My assumption is that the instructions we wanted to avoid RAUW were only the EHPad, not all the token instructions.</div></div><div>So I'm changing it into RAUW all non-EHPad instructions and delete all non-EHPad instructions.</div><div><br></div><div>But maybe my assumption is incorrect and there are token instructions that are non-EHPad that we want to skip too?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 16, 2020 at 7:55 PM Eli Friedman <<a href="mailto:efriedma@quicinc.com">efriedma@quicinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_180345698428325317WordSection1">
<p class="MsoNormal">In general, we have to RAUW before we erase an instruction in dead code; even if we know the instruction is dead, it could still have uses in other dead code.  If an instruction still has uses, we can’t erase it.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-Eli<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> <b>On Behalf Of
</b>Alexandre Isoard via llvm-dev<br>
<b>Sent:</b> Tuesday, June 16, 2020 7:33 PM<br>
<b>To:</b> David Majnemer <<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [EXT] [llvm-dev] InstCombine doesn't delete instructions with token<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello David,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am having an issue with some custom intrinsics that return a token value: InstCombine deletes the users of the token but not the instruction that creates the token itself. The IR is still valid but it's wasted.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">The source of the issue is coming from an old patch of yours:<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">commit 7204cff0a121ebc770cf81f7f94679ae7324daae<br>
Author: David Majnemer <<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>><br>
Date:   Fri Nov 6 21:26:32 2015 +0000<br>
<br>
    [InstCombine] Don't RAUW tokens with undef<br>
    <br>
    Let SimplifyCFG remove unreachable BBs which define token instructions.<br>
    <br>
    llvm-svn: 252343<br>
<br>
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp<br>
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp<br>
@@ -3012,7 +3012,7 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,<br>
     while (EndInst != BB->begin()) {<br>
       // Delete the next to last instruction.<br>
       Instruction *Inst = &*--EndInst->getIterator();<br>
-      if (!Inst->use_empty())<br>
+      if (!Inst->use_empty() && !Inst->getType()->isTokenTy())<br>
         Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); <br>
-      if (Inst->isEHPad()) { <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+      if (Inst->isEHPad() || Inst->getType()->isTokenTy()) { <br>
         EndInst = Inst;<br>
@@ -3022,7 +3022,8 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,<br>
         ++NumDeadInst;<br>
         MadeIRChange = true;<br>
       }<br>
       Inst->eraseFromParent();<br>
     }<br>
   }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I believe the goal was to avoid RAUW the EHPad (as we don't delete the associated EHRet) and not skip all of the token instructions. At least you only test on EHPad in the associated unit test.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">In which case we could instead do:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">     while (EndInst != BB->begin()) {<br>
       // Delete the next to last instruction.<br>
       Instruction *Inst = &*--EndInst->getIterator();<br>
-      if (!Inst->use_empty())<br>
+      if (!Inst->use_empty() && !Inst->isEHPad())<br>
         Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); <br>
       if (Inst->isEHPad()) { <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">         EndInst = Inst;<br>
@@ -3022,7 +3022,8 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,<br>
         ++NumDeadInst;<br>
         MadeIRChange = true;<br>
       }<br>
       Inst->eraseFromParent();<br>
     }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Is my assumption correct?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Note that the code is now in llvm::removeAllNonTerminatorAndEHPadInstructions of llvm/lib/Transforms/Utils/Local.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><b>Alexandre Isoard</b><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div>