<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" id="owaParaStyle"></style><style type="text/css"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<p class="p1"><span class="s1">Hello, </span></p>
<p class="p2"><span class="s1"></span><br>
</p>
<p class="p1"><span class="s1">I found that GVN doesn't promote identical sequence of instructions in if and else branch to their common predecessors. For example, for the following code snippet</span></p>
<p class="p2"><span class="s1"></span><br>
</p>
<p class="p1"><span class="s1">pred:</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>…</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>br i1 %cmp, label %if, label %else</span></p>
<p class="p1"><span class="s1">if:</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>%incdec.ptr.1 = getelementptr inbounds i8, i8* %ptr, i64 1</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>%cast1 = ptrtoint i8* %incdec.ptr.1 to i64</span></p>
<p class="p1"><span class="s1">   <span class="Apple-tab-span"> </span>…</span></p>
<p class="p1"><span class="s1">else:</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>%incdec.ptr.2 = getelementptr inbounds i8, i8* %ptr, i64 1</span></p>
<p class="p1"><span class="s1"><span class="Apple-tab-span"></span>%cast2 = ptrtoint i8* %incdec.ptr.2 to i64</span></p>
<p class="p2"><span class="s1"></span><br>
</p>
<p class="p1"><span class="s1">GVN doesn't move instructions in 'if' and 'else' blocks to 'pred' block even though it knows that incdec.ptr.1/case1 has a same value number with incdec.ptr.2/cast2. I see a case where this kind of redundancy confuses following
 optimization passes and ends up generating suboptimal code. </span></p>
<p class="p2"><span class="s1"></span><br>
</p>
<p class="p1"><span class="s1">From the GVN implementation, it seems that transformation is performed only when the "leader" value dominates the other value, so it cannot handle a case like the above example. I wonder if this is by design or just a missing
 feature. </span></p>
<p class="p2"><span class="s1"></span><br>
</p>
<p class="p1"><span class="s1">Thanks,</span></p>
<p class="p1"><span class="s1">Taewook</span></p>
</div>
</body>
</html>