[PATCH] D90106: [JumpThreading] Set edge probabilities when creating basic blocks

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 24 15:32:36 PDT 2020


kazu created this revision.
kazu added reviewers: wmi, efriedma.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
kazu requested review of this revision.

This patch teaches the jump threading pass to set edge probabilities
whenever the pass creates new basic blocks.

Without this patch, the compiler sometimes produces non-deterministic
results.  The non-determinism comes from the jump threading pass using
stale edge probabilities in BranchProbabilityInfo.  Specifically, when
the jump threading pass creates a new basic block, we don't initialize
its outgoing edge probability.

Edge probabilities are maintained in:

  DenseMap<Edge, BranchProbability> Probs;

in class BranchProbabilityInfo, where Edge is an ordered pair of
BasicBlock * and a successor index declared as:

  using Edge = std::pair<const BasicBlock *, unsigned>;

Probs maps edges to their corresponding probabilities.

Now, we rarely remove entries from this map, so if we happen to
allocate a new basic block at the same address as a previously deleted
basic block with an edge probability assigned, the newly created basic
block appears to have an edge probability, albeit a stale one.

This patch fixes the problem by explicitly setting edge probabilities
whenever the jump threading pass creates new basic blocks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90106

Files:
  llvm/lib/Transforms/Scalar/JumpThreading.cpp
  llvm/test/Transforms/JumpThreading/thread-prob-1.ll
  llvm/test/Transforms/JumpThreading/thread-prob-2.ll
  llvm/test/Transforms/JumpThreading/thread-prob-3.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90106.300510.patch
Type: text/x-patch
Size: 6217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201024/2ae9708f/attachment.bin>


More information about the llvm-commits mailing list