[PATCH]Avoid redundant select node in early if conversation pass

yi_jiang yjiang at apple.com
Thu Jun 18 12:34:19 PDT 2015


Hi, 

We found that early if-conversion pass may introduce some redundant select node. Please see the example below, I use llvm IR here just to make it a little easier to read although early if-conversion is dealing machine instructions.  When we if-convert a diamond below, If the tail basic block(while.body) has extra predecessors(while.body.lr.ph), we need to insert select in the head basic block(while.cond) and rewrite the PHI in the tail basic block(while.body). However, if this select node is actually selecting same value, that is redundant. In our case, it is the %j.012 with incoming value of %inc from both %if.then and %if.else. And since early if conversation is pretty late in codegen so the latter passes won’t be able to remove this redundancy. This patch is to remove this redundancy. Bzip2 decompression will benefit from this patch. 

while.cond:  ; Head BB
  ...
  br i1 %cmp2, label %if.then, label %if.else

if.then:   ;TBB
  %inc2 = add nsw i32 %i.011, 1
  br label %while.body

if.else:   ;FBB
  %dec = add nsw i32 %i.011, -1
  br label %while.body

while.body:   ;Tail BB
  %j.012 = phi i32 [ %sub, %while.body.lr.ph ], [ %inc, %if.then ], [ %inc, %if.else ]   ;we dont need a select of %inc and %inc from the TBB/FBB in Head BB
  %i.011 = phi i32 [ %a, %while.body.lr.ph ], [ %inc2, %if.then ], [ %dec, %if.else ]    ;we DO need a select of %inc2 and %dec from the TBB/FBB in Head BB
  ...
  br i1 %cmp1, label %while.end, label %while.cond





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150618/7b360d8b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ifcvt.patch
Type: application/octet-stream
Size: 3621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150618/7b360d8b/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150618/7b360d8b/attachment-0001.html>


More information about the llvm-commits mailing list