[SimplifyCFG] use profile metadata to refine merging branch conditions
authorSanjay Patel <spatel@rotateright.com>
Mon, 22 Mar 2021 20:45:54 +0000 (16:45 -0400)
committerSanjay Patel <spatel@rotateright.com>
Mon, 22 Mar 2021 20:49:21 +0000 (16:49 -0400)
commit27ae17a6b0145a559c501c35ded0ab4e9dd69e8e
tree3c1729cea64fb4bb9eadd92935c9da97c23795b5
parent424bf5d8918f6356f1b8e99205c5fc8b4783ca22
[SimplifyCFG] use profile metadata to refine merging branch conditions

This is one step towards solving:
https://llvm.org/PR49336

In that example, we disregard the recommended usage of builtin_expect,
so an expensive (unpredictable) branch is folded into another branch
that is guarding it.
Here, we read the profile metadata to see if the 1st (predecessor)
condition is likely to cause execution to bypass the 2nd (successor)
condition before merging conditions by using logic ops.

Differential Revision: https://reviews.llvm.org/D98898
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/PGOProfile/chr.ll
llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll