[llvm-commits] [PATCH] Preserve branch weight metadata when creating switches in SimplifyCFG

Alastair Murray alastairmurray42 at gmail.com
Fri Aug 17 11:45:34 PDT 2012


Hello all,

Evan Cheng is CC'ed because he originally suggested I look at this 
issue, Manman Ren is CC'ed because he has expressed interest in this topic.

Please review the attached patch. Note: I don't have commit rights.

The patch preserves branch weight metadata in SimplifyCFG in various 
situations where switch instructions are inserted (converting linked 
if-statements or icmp's to a switch instruction, merging switch 
instructions, merging an if-statement into a switch instruction).

As metadata can not be assumed to be consistent with the current form of 
the IR the added code only preserves metadata if it seems consistent.

It has been tested with both profiling data (over projects/test-suite) 
and __builtin_expect.  In the case of __builtin_expect the branch 
weights are scaled when creating switch instructions to account for the 
different probability model.  if (C1) { A } else if (C2) { B} means P(B) 
= P(C2 | !C1), but a switch statement just models the probability as P(C2).

Regards,
Alastair Murray
-------------- next part --------------
A non-text attachment was scrubbed...
Name: preserve_switch_branch_metadata.patch
Type: text/x-patch
Size: 28121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120818/a781321d/attachment.bin>


More information about the llvm-commits mailing list