OSDN Git Service

[PPC] Correctly adjust branch probability in PPCReduceCRLogicals
authorGuozhi Wei <carrot@google.com>
Fri, 31 May 2019 16:11:17 +0000 (16:11 +0000)
committerGuozhi Wei <carrot@google.com>
Fri, 31 May 2019 16:11:17 +0000 (16:11 +0000)
commit34b6df0acd0c31038c2a2db7b9fa28b7208d9d43
tree41fcd2b01a0092d265c1b6cbaed877457c62bdd8
parentdbb88f14e21b5353931086cf7a106a664c44d704
[PPC] Correctly adjust branch probability in PPCReduceCRLogicals

In PPCReduceCRLogicals after splitting the original MBB into 2, the 2 impacted branches still use original branch probability. This is unreasonable. Suppose we have following code, and the probability of each successor is 50%.

    condc = conda || condb
    br condc, label %target, label %fallthrough

It can be transformed to following,

    br conda, label %target, label %newbb
  newbb:
    br condb, label %target, label %fallthrough

Since each branch has a probability of 50% to each successor, the total probability to %fallthrough is 25% now, and the total probability to %target is 75%. This actually changed the original profiling data. A more reasonable probability can be set to 70% to the false side for each branch instruction, so the total probability to %fallthrough is close to 50%.

This patch assumes the branch target with two incoming edges have same edge frequency and computes new probability fore each target, and keep the total probability to original targets unchanged.

Differential Revision: https://reviews.llvm.org/D62430

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362237 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/BranchProbability.h
lib/Target/PowerPC/PPCReduceCRLogicals.cpp
test/CodeGen/PowerPC/reduce_cr.ll [new file with mode: 0644]
test/CodeGen/PowerPC/select-i1-vs-i1.ll