[PATCH][CodeGenPrepare] Split branch conditions into multiple branches.

Juergen Ributzka juergen at apple.com
Thu Dec 4 14:57:29 PST 2014


Hi @ll,

SimplifyCFG likes to fold conditional branches to a common destination into a single conditional branch, where the original conditions can be combined with an and/or instruction (FoldBranchToCommonDest).

Example:
bb1:
  %0 = icmp eq i32 %a, 0
  br i1 %0, label %bb3, label %bb2, !prof !0

bb2:
  %1 = icmp eq i32 %b, 0
  br i1 %1, label %bb3, label %bb4, !prof !1

is optimized to:

bb1:
  %0 = icmp eq i32 %a, 0
  %1 = icmp eq i32 %b, 0
  %or.cond = or i1 %0, %1
  br i1 %or.cond, label %bb3, label %bb4, !prof !0


During SelectionDAG time this transformation is reversed, because it is usually more efficient (code size and performance) to express this code as multiple branches. SelectionDAG can do this, because it can generate new MachineBasicBlocks. FastISel on the other side cannot do this and generates inefficient code (I see 10% regression on some benchmarks).

The attached patch fixes this by performing the splitting early during CodeGenPrepare. In theory this code can be shared now by SelectionDAG and FastISel and the original implementation in SelectionDAG could be removed.


Any comments and/or ideas about this approach in general? Is there a better way to do this?

Thanks

Cheers,
Juergen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Move-function-to-obtain-branch-weights-into-the-Bran.patch
Type: application/octet-stream
Size: 5185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141204/bfb231d1/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-CodeGenPrepare-Split-branch-conditions-into-multiple.patch
Type: application/octet-stream
Size: 7563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141204/bfb231d1/attachment-0001.obj>
-------------- next part --------------


 


More information about the llvm-commits mailing list