[PATCH] D113342: [LoopRotate] Add branch_weights metadata for rotated branch

Bin Cheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 6 04:50:14 PDT 2021


bin.cheng created this revision.
bin.cheng added reviewers: fhahn, mkazantsev.
bin.cheng added a project: LLVM.
Herald added subscribers: lxfind, zzheng, hiraditya.
bin.cheng requested review of this revision.
Herald added a subscriber: llvm-commits.

Hi,
When loop is rotated, the exit branch becomes a normal branch go to or skip the rotated loop. Since it's duplicated from loop exit branch, the result branch should have the same BPI as loop exit branch. However, the branch after rotation has nothing to do with the original loop and would very likely be predicated as 50/50% probability in BPI.  This patch adds branch_weights metadata for it so it can be predicted with the same probability as loop exit branch.  I also updated and looked into related tests and can confirm the change is expected. 
Note that I searched around the code base but didn't see many use of branch_weight metadata, I assume it's mostly for use of profiled probability?  So maybe it's inappropriate to use branch_weights metadata in this case, unfortunately, I  didn't come up with any other better idea.  Much appreciated for any comments that if I should handle the issue differently.

Thanks,
bin


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113342

Files:
  llvm/include/llvm/Analysis/BranchProbabilityInfo.h
  llvm/lib/Analysis/BranchProbabilityInfo.cpp
  llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
  llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll
  llvm/test/Transforms/LoopRotate/callbr.ll
  llvm/test/Transforms/LoopRotate/loopexitinglatch.ll
  llvm/test/Transforms/LoopSimplify/merge-exits.ll
  llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll
  llvm/test/Transforms/PhaseOrdering/AArch64/matrix-extract-insert.ll
  llvm/test/Transforms/PhaseOrdering/ARM/arm_add_q7.ll
  llvm/test/Transforms/PhaseOrdering/ARM/arm_fill_q7.ll
  llvm/test/Transforms/PhaseOrdering/ARM/arm_mult_q15.ll
  llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop.ll
  llvm/test/Transforms/PhaseOrdering/X86/pixel-splat.ll
  llvm/test/Transforms/PhaseOrdering/X86/pr48844-br-to-switch-vectorization.ll
  llvm/test/Transforms/PhaseOrdering/X86/spurious-peeling.ll
  llvm/test/Transforms/PhaseOrdering/X86/vdiv.ll
  llvm/test/Transforms/PhaseOrdering/deletion-of-loops-that-became-side-effect-free.ll
  llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113342.385262.patch
Type: text/x-patch
Size: 31199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211106/2f244eab/attachment.bin>


More information about the llvm-commits mailing list