Are you sure this is really advantageous? '%c' is only one variable, but when you add the constant propagation, '%c' and false/true are two different variables. Thus<div><br> define i1 @t1(i1 %c) {<br>   br i1 %c, label %t, label %f<br>
 t:<br>   ret i1 %c<br> f:<br>   ret i1 %c<br> }</div><div>should be </div><div>  br i1 R0, label %t, label %f</div><div>t:</div><div>  ret R0 </div><div>f: </div><div>  ret R0</div><div><br></div><div>However, with your pass</div>
<div> define i1 @t1(i1 %c) {<br>   br i1 %c, label %t, label %f<br> t:<br>   ret i1 true<br> f:<br>   ret i1 false<br> }</div><div>will be</div> define i1 @t1(i1 %c) {<br>   br i1 R0, label %t, label %f<br> t:<div>   R1 = true<br>
   ret i1 R1<br> f:</div><div>   R1 = false<br>   ret i1 R1<br> }</div><div><br></div><div><div>I am thinking X86 where '%c' would be allocated a register and the false/true statement would be allocated a different register which would be EAX/AX on the x86 machine. </div>
<div><br></div><div>Honestly, I believe this pattern could be conditional constant propagation / conditional re-materialization in the spiller. LLVM uses the spiller to propagate constants. This pass would be useful to identify some conditional re-materializations. You should look into hacking the spiller and see if this can be added to it.</div>
<div><br></div><div>- My 2 cents,</div><div>Jeff Kunkel</div><div><br><div class="gmail_quote">On Mon, Feb 7, 2011 at 7:50 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi all, I wrote a little pass (attached) which does the following: if it sees a<br>
conditional branch instruction then it replaces all occurrences of the condition<br>
in the true block with "true" and in the false block with "false".  Well, OK, it<br>
is a bit more sophisticated (and a bit more careful!) than that but you get the<br>
idea.  It will turn this<br>
  define i1 @t1(i1 %c) {<br>
    br i1 %c, label %t, label %f<br>
  t:<br>
    ret i1 %c<br>
  f:<br>
    ret i1 %c<br>
  }<br>
into this<br>
  define i1 @t1(i1 %c) {<br>
    br i1 %c, label %t, label %f<br>
  t:<br>
    ret i1 true<br>
  f:<br>
    ret i1 false<br>
  }<br>
for example.  Curiously enough LLVM doesn't seem to have a pass that does this.<br>
I took a look at the effect on the testsuite by scheduling a run of this pass<br>
just after each run of -correlated-propagation.  In spite of being so simple<br>
(not to say simplistic) it has an enormous positive impact on Ada code and a<br>
substantial positive impact throughout the LLVM test-suite (I didn't check that<br>
programs still work after running the pass, so it could be that it has such a<br>
big effect because it is wrong!).<br>
<br>
So... should this kind of logic be incorporated into LLVM?  Perhaps as part of<br>
an existing pass like -correlated-propagation?<br>
<br>
It would be easy to make the pass a bit more powerful.  For example if the<br>
condition was "X == 0" then it could also replace X with 0 everywhere in the<br>
true block.<br>
<br>
Ciao, Duncan.<br>
<br>
PS: This was inspired by PR9004.<br>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>