<div dir="ltr"><div dir="ltr">Hi all,<div><br></div><div>I'm working on some LLVM 7 code and I was wondering if there exists an optimization pass (perhaps that exists in a later version of LLVM) that does the following. Or if not, a good pass for me to implement this inside of may be.</div><div><br></div><div>Suppose you have the following loop:</div><div><br></div><div><div><font face="monospace, monospace">for:                ; preds = %entry, %for</font></div><div><font face="monospace, monospace">  %phi = phi double [ %entry_value, %entry ], [ %selected_value, %for ]</font></div><div><font face="monospace, monospace">  %condition = ...</font></div><div><font face="monospace, monospace">  %</font><span style="font-family:monospace,monospace">selected_value</span><font face="monospace, monospace"> = select i1 %</font><span style="font-family:monospace,monospace">condition</span><font face="monospace, monospace">, double %inner_value, double %any_value</font></div><div><span style="font-family:monospace,monospace">  br i1 %</span><span style="font-family:monospace,monospace">condition</span><span style="font-family:monospace,monospace">, label %for, label %loop_exit</span><br></div></div><div><span style="font-family:monospace,monospace"><br></span></div><div>In this case, (and similarly cases where the loop condition is the same as the select condition), we may simply replace %selected_value in the for loop with %inner_value from the select (and therefore remove the select).</div><div><br></div><div><div>This type of structure comes up frequently in some codes I'm looking at and figured I'd check if anyone has something to deal with it already before I implement my own (and try to upstream).</div><div><br></div><div>Cheers,</div></div><div>Billy Moses</div></div></div>