[PATCH] D159322: LoopVectorize: Set branch_weight for conditional branches

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 5 13:47:46 PDT 2023


MatzeB added a comment.

> Slightly different off-topic from the change itself, but for this to be future proof, I'm also wondering that eventually should we have the BranchInst::Create API for cond branch to always ask for branch weights if the parent function has non-zero entry count.

I don't think we can enforce this. As when the API itself creates an instruction without adding it to a basic block, so you don't know about the surrounding function. Also forcing things would disallow some programming patterns like adding the weights later (I can't think of a use case for that admittedly, but I also wouldn't say this will never be useful)...

Admittedly I was contemplating whether adding an optional parameter to the API would make sense but it feels inconsistent... We have lots of `XXXInst::Create` functions but they all are like a low-level API that take the minimum amount of parameters necessary to construction an instruction and I would feel odd to start being opinionated and allow some metadata for convenience. Also usually we have the "convenience" style APIs in `IRBuilder::createXXX` already the code just didn't happen to use them here...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159322/new/

https://reviews.llvm.org/D159322



More information about the llvm-commits mailing list