Open weiguozhi opened 7 years ago
We're doing some experiments to see how this example behaves on P9.
The iterator "it" is incremented in each iteration, and it is compared to the same value vec->end(), so we can expect the condition is false for most times, and then it is true, and then false again ... So this branch is highly predictable.
This is a good point. We should be able to come up with a reasonable set of 'predictibility' heuristics (just like we have for branch probabilities).
Extended Description
On power, use ISEL or cmp/br is a general hard problem. But if we can point out the branch is highly predictable (either through runtime profiling or static estimate), we should use cmp/br.
Following is a test case simplified from real world code.
include
typedef std::vector MyVec;
int foo(int iters, MyVec* vec) {
MyVec::const_iterator it = vec->begin();
for (int i = 0; i < iters; ++i, ++it) { if (it == vec->end()) { it = vec->begin(); }
if (*it >= iters) return 1; } return 0; }
The iterator "it" is incremented in each iteration, and it is compared to the same value vec->end(), so we can expect the condition is false for most times, and then it is true, and then false again ... So this branch is highly predictable. In our code, cmp/br is 2x faster than isel.
LLVM generates following code, which uses ISEL
BB#0: # %entry
BB#1: # %for.body.lr.ph
.LBB0_2: # %for.body
=>This Inner Loop Header: Depth=1
BB#3: # %for.inc
.LBB0_4: li 3, 0 clrldi 3, 3, 32 blr .LBB0_5: li 3, 1 clrldi 3, 3, 32 blr