[PATCH] D21299: [Codegen Prepare] Swap commutative binops before splitting branch condition.

Balaram Makam via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 15:22:42 PDT 2016


bmakam added a comment.

In http://reviews.llvm.org/D21299#482177, @t.p.northover wrote:

> > FWIW, this heuristic is not assigning any branch probabilities based on the range size, it only ranks the commutative binary operands based on the generic assumption that if we have two conditions a != 0 and b == 2, it is more likely that a != 0 than b == 2
>
>
> And I still think that's not obviously true. Integers actually used often take a very limited number of values, and this seems like a common idiom to me:
>
>   int res = some_func();
>   if (res < 0)
>     llvm_unreachable("WTF happened");
>   else if (res == 0)
>     [...]
>   


This is exactly the idiom I am trying to clarify. This change does not influence the branch direction for the idiom like above at all. All this change targets is code like

  if (cond1 && cond2)
    do_something

or

  if (cond1 || cond2)
    do_something

Currently, the codegen decides to split the condition into branches for targets which have cheap jump instructions and there is some flexibility in the order of the blocks containing cond1 and cond2. This patch is trying to rank cond1 and cond2 in such a way that it is profitable in most cases and is always consistent independent of earlier optimizations.

Thanks,
Balaram


http://reviews.llvm.org/D21299





More information about the llvm-commits mailing list