[PATCH] D138132: [JumpThreading] Preserve profile metadata during select unfolding

Dmitri Gribenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 02:34:52 PST 2023


gribozavr2 added a comment.

Unfortunately, this change causes assertion failures and I'm going to revert it.

Addition in this line can overflow: `BP.emplace_back(BranchProbability(TrueWeight, TrueWeight + FalseWeight));`. As a result, the constructor of `BranchProbability()` can trigger an assertion.

Here's an example in a debugger:

  frame #9: 0x000055556f3d47ea clang`llvm::JumpThreadingPass::unfoldSelectInstr(this=0x0000068f36045618, Pred=0x0000068f360e55a0, BB=0x0000068f3613d1a0, SI=0x0000068f36b8a6a0, SIUse=0x0000068f397a53d0, Idx=1) at JumpThreading.cpp:2797:23
     2794     if (extractBranchWeights(*SI, TrueWeight, FalseWeight) &&
     2795         (TrueWeight + FalseWeight) != 0) {
     2796       SmallVector<BranchProbability, 2> BP;
  -> 2797       BP.emplace_back(BranchProbability(TrueWeight, TrueWeight + FalseWeight));
     2798       BP.emplace_back(BranchProbability(FalseWeight, TrueWeight + FalseWeight));
     2799       BPI->setEdgeProbability(Pred, BP);
     2800     }
  (lldb) p TrueWeight
  (uint64_t) $0 = 2147483648
  (lldb) p FalseWeight
  (uint64_t) $1 = 2147483648
  (lldb) down
  frame #8: 0x0000555571acc3a6 clang`llvm::BranchProbability::BranchProbability(this=0x00007fffffff0d80, Numerator=2147483648, Denominator=0) at BranchProbability.cpp:41:3
     38   #endif
     39
     40   BranchProbability::BranchProbability(uint32_t Numerator, uint32_t Denominator) {
  -> 41     assert(Denominator > 0 && "Denominator cannot be 0!");
     42     assert(Numerator <= Denominator && "Probability cannot be bigger than 1!");
     43     if (Denominator == D)
     44       N = Numerator;
  (lldb) p Denominator
  (uint32_t) $2 = 0

Unfortunately, I don't have a reduced IR example, but hopefully this should be enough to debug and fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138132



More information about the llvm-commits mailing list