[PATCH] D31647: [JumpThreading] Propagate branch hint (biased branch weight) metadata

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 23:01:35 PDT 2017


inouehrs created this revision.

In the following motivating example, we want to propagate branch hint (__builtin_expect) to the conditional branch in callee method `foo`. However, in the current LLVM, this branch hint may be simply discarded when the conditional branch in the caller method `bar` is eliminated in the jump threading pass.

  inline bool foo(int flag) {
  	if (flag) return false;
  	...
  	return true;
  }
  
  bool bar(...) {
  	...
  	if (__builtin_expect(!foo(flag), 0)) {
  		// cold block
  		return false;
  	}
  	...

The current jump threading pass adjusts branch and block frequency profile data, but the branch hint may exist as a metadata even the full profile information is not available.

This patch enhances the jump threading pass to propagate the branch hint metadata as follow:

1. If the conditional branch to be modified has a biased (e.g. 1:2000) branch weight metadata, and the target BB of the colder branch edge has only one incoming edge, we mark this BB as a cold block. In the case of the above example, the return block in the `bar` is the cold block.
2. We identify the cold region, i.e. the basic blocks post-dominated by the cold block. The return block in the `foo` is in the cold region since it is post-dominated by the cold block after jump threading.
3. We set the branch hint for the conditional branches that jump into the cold region from non-cold region.


https://reviews.llvm.org/D31647

Files:
  lib/Transforms/Scalar/JumpThreading.cpp
  test/Transforms/JumpThreading/branch-metadata.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31647.94006.patch
Type: text/x-patch
Size: 12312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/10ecda4e/attachment.bin>


More information about the llvm-commits mailing list