<div dir="ltr">This is .. not quite right.<div>It marks terminators of predecessor edges live, but that's not what you should do. You should mark terminators of CD(predecessors) as live.</div><div>See keith cooper's slides at <a href="https://www.clear.rice.edu/comp512/Lectures/10Dead-Clean-SCCP.pdf">https://www.clear.rice.edu/comp512/Lectures/10Dead-Clean-SCCP.pdf</a><br></div><div><br></div><div>You can also find the same thing in the original SSA paper <a href="http://compilers.cs.uni-saarland.de/teaching/cc/2013/papers/p451-cytron.pdf">http://compilers.cs.uni-saarland.de/teaching/cc/2013/papers/p451-cytron.pdf</a> on page 480 <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 7, 2016 at 7:13 PM, David Callahan <span dir="ltr"><<a href="mailto:dcallahan@fb.com" target="_blank">dcallahan@fb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">david2050 updated this revision to Diff 70635.<br>
david2050 added a comment.<br>
<br>
Change handling of PHI nodes to force predecessors live<br>
<br>
<br>
<a href="https://reviews.llvm.org/D23824" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D23824</a><br>
<br>
Files:<br>
lib/Transforms/Scalar/ADCE.cpp<br>
<br>
Index: lib/Transforms/Scalar/ADCE.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/Transforms/Scalar/ADCE.cpp<br>
+++ lib/Transforms/Scalar/ADCE.cpp<br>
@@ -58,6 +58,8 @@<br>
bool Live = false;<br>
/// True when this block ends in an unconditional branch.<br>
bool UnconditionalBranch = false;<br>
+ /// True when this block is known to have live PHI nodes.<br>
+ bool HasLivePhiNodes = false;<br>
<br>
/// Quick access to the LiveInfo for the terminator,<br>
/// holds the value &InstInfo[Terminator]<br>
@@ -109,6 +111,9 @@<br>
void markLiveInstructions();<br>
/// Mark an instruction as live.<br>
void markLive(Instruction *I);<br>
+<br>
+ /// Mark terminators of control predecessors of a PHI node live.<br>
+ void markPhiLive(PHINode *PN);<br>
<br>
/// Record the Debug Scopes which surround live debug information.<br>
void collectLiveScopes(const DILocalScope &LS);<br>
@@ -269,15 +274,18 @@<br>
// where we need to mark the inputs as live.<br>
while (!Worklist.empty()) {<br>
Instruction *LiveInst = Worklist.pop_back_val();<br>
+ DEBUG(dbgs() << "work live: "; LiveInst->dump(););<br>
<br>
// Collect the live debug info scopes attached to this instruction.<br>
if (const DILocation *DL = LiveInst->getDebugLoc())<br>
collectLiveScopes(*DL);<br>
<span class=""><br>
- DEBUG(dbgs() << "work live: "; LiveInst->dump(););<br>
</span> for (Use &OI : LiveInst->operands())<br>
if (Instruction *Inst = dyn_cast<Instruction>(OI))<br>
markLive(Inst);<br>
+<br>
+ if (auto *PN = dyn_cast<PHINode>(LiveInst))<br>
+ markPhiLive(PN);<br>
}<br>
markLiveBranchesFromControlDep<wbr>endences();<br>
<br>
@@ -348,6 +356,18 @@<br>
collectLiveScopes(*IA);<br>
}<br>
<br>
+void AggressiveDeadCodeElimination:<wbr>:markPhiLive(llvm::PHINode *PN) {<br>
+ auto &Info = BlockInfo[PN->getParent()];<br>
+ // Only need to check this once per block.<br>
+ if(Info.HasLivePhiNodes)<br>
+ return;<br>
+ Info.HasLivePhiNodes = true;<br>
+<br>
+ // Mark terminators of all predecessors live.<br>
+ for (auto *PredBB : predecessors(Info.BB))<br>
+ markLive(PredBB-><wbr>getTerminator());<br>
+}<br>
+<br>
void AggressiveDeadCodeElimination:<wbr>:<wbr>markLiveBranchesFromControlDep<wbr>endences() {<br>
<br>
if (BlocksWithDeadTerminators.<wbr>empty())<br>
@@ -382,6 +402,11 @@<br>
}<br>
}<br>
<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+//<br>
+// Routines to update the CFG and SSA information before removing dead code.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
bool AggressiveDeadCodeElimination:<wbr>:removeDeadInstructions() {<br>
<br>
// The inverse of the live set is the dead set. These are those instructions<br>
<br>
<br>
</blockquote></div><br></div>