[LLVMdev] Possible Phi Removal Pass?

bdavis at cs.fsu.edu bdavis at cs.fsu.edu
Thu Nov 10 09:08:56 PST 2011


Looking through this mailing list's archives, I've found that the most  
common fix attempted for removing phi instructions is to use the  
reg2mem pass. However I'm also finding that this does no guarantee the  
removal of all phi instructions.

I want to write a pass to remove phi instructions without changing  
register/memory usage. Does this sort of translation of phi  
instructions seem reasonable? :

===============================================================
; Original stripped code example

entry:
   ...
   br label %for.body

for.body:                ; preds = %entry, %sw.epilog
   %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %sw.epilog ]
   %j.02 = phi i32 [10, %entry ], [ %j.2, %sw.epilog ]
   ...

sw.epilog:               ; preds = ...
   ...
   br i1 %exitcond, label %for.end, label %for.body

; End original stripped code example
===============================================================
===============================================================
; Post-pass

entry:
   ...
   br label %entry.to.for.body

entry.to.for.body:          ; preds = %entry
   %indvar = add i32 0, 0
   %j.02 = add i32 10, 0
   br label %for.body

for.body:                   ; preds = %entry.to.for.body,  
%sw.epilog.to.for.body
   ; both phi instructions removed
   ...

sw.epilog:                  ; preds = ...
   ...
   br i1 %exitcond, label %for.end, label %sw.epilog.to.for.body

sw.epilog.to.for.body:      ; preds = %sw.epilog
   %indvar = add i32 %indvar.next, 0
   %j.02 = add i32 %j.2, 0
   br label %for.body

; End post-pass code example
===============================================================

This simply adds a basic block as an intermediate destination when  
branching to a basic block that has a phi instruction in it. This new  
intermediate block has exactly 1 predecessor and exactly 1 successor,  
so it can handle the assignment required by the phi.

Is there some error in this that I may be missing, or does this seem  
to be a reasonable pass to write?

Thanks,
Brandon

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.






More information about the llvm-dev mailing list