<div dir="ltr">result of opt -gvn on pr34471.ll:<div><div>; ModuleID = 'foo.ll'</div><div>source_filename = "foo.ll"</div><div><br></div><div>define i32 @PR34471(i32 %x) {</div><div>entry:</div><div>  switch i32 %x, label %else3 [</div><div>    i32 17, label %return</div><div>    i32 19, label %if19</div><div>    i32 42, label %if42</div><div>  ]</div><div><br></div><div>if19:                                             ; preds = %entry</div><div>  br label %return</div><div><br></div><div>if42:                                             ; preds = %entry</div><div>  br label %return</div><div><br></div><div>else3:                                            ; preds = %entry</div><div>  br label %return</div><div><br></div><div>return:                                           ; preds = %else3, %if42, %if19, %entry</div><div>  %r = phi i32 [ 19, %if19 ], [ 42, %if42 ], [ 0, %else3 ], [ 17, %entry ]</div><div>  ret i32 %r</div><div>}</div></div><div><br></div><div>-correlated-propagation gives the same answer, as do -newgvn and a few other passes.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 22, 2017 at 10:06 AM, Daniel Berlin via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dberlin added a comment.<br>
<br>
Hey Sanjay,<br>
GVN/NewGVN/et al will undo this transform, and propagate constants. In fact, i expect pretty much any pass that can, will.<br>
<br>
This definitely belongs in the late simplification category at best.<br>
<br>
More than that, i'm concerned this is the wrong fix.<br>
<br>
Why is the right answer  to undo the transform (which will cause fights between passes)  in simplifycfg instead of improving the codegen to recognize the issue?<br>
<br>
It seems the same code you are using to detect and undo the transforrm in simplification could be used to codegen it better.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D39011" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D39011</a><br>
<br>
<br>
<br>
</div></div></blockquote></div><br></div>