[llvm-commits] Edge dominance in the presence of multiple edges between two BB

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Aug 10 11:30:48 PDT 2012


> I will try to code an hybrid.

I was not able to make it a lot better. The way the original patch
avoided the loop was by getting the wrong answer in

define i32 @f(i32 %i) {
bb0:
  switch i32 %i, label %bb1 [
    i32 1, label %bb2
    i32 2, label %bb2
  ]
bb1:
  br label %bb2
bb2:
  %r = phi i32 [ %i, %bb0 ], [ %i, %bb0 ], [ 5, %bb1 ]
  ret i32 %r
}

It would says that the first edge would dominate the first use in the
phi and the second edge dominate the second. There are no guarantees
about the order we see the basic blocks, so we have to look at all of
them.

An alternative that I implemented in this patch is to walk the
predecessors. It avoids a virtual call per loop iteration,  but needs
to call getUser. I have also moved one of the calls to isSingleEdge
after other checks.

Note that normally this is only called on invokes, with always have
two successors. The only case this will be used in other instructions
is in GVN itself. This suggests that the version iterating the
successors is probably better than the one iterating the predecessors.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 3170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120810/6face0d8/attachment.obj>


More information about the llvm-commits mailing list