[all-commits] [llvm/llvm-project] c91487: [JumpThreading] Set edge probabilities when creati...

kazutakahirata via All-commits all-commits at lists.llvm.org
Tue Oct 27 16:08:06 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c91487769d80487eba1712a7a172a1c8977a9b4f
      https://github.com/llvm/llvm-project/commit/c91487769d80487eba1712a7a172a1c8977a9b4f
  Author: Kazu Hirata <kazu at google.com>
  Date:   2020-10-27 (Tue, 27 Oct 2020)

  Changed paths:
    M llvm/lib/Transforms/Scalar/JumpThreading.cpp
    A llvm/test/Transforms/JumpThreading/thread-prob-1.ll
    A llvm/test/Transforms/JumpThreading/thread-prob-2.ll
    A llvm/test/Transforms/JumpThreading/thread-prob-3.ll

  Log Message:
  -----------
  [JumpThreading] Set edge probabilities when creating basic blocks

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.

Differential Revision: https://reviews.llvm.org/D90106




More information about the All-commits mailing list