[PATCH] D62126: [CorrelatedValuePropagation] Fix prof branch_weights metadata handling for SwitchInst

Yevgeny Rouban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 07:16:55 PDT 2019

yrouban marked an inline comment as done.
yrouban added inline comments.

Comment at: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp:398
     ConstantFoldTerminator(BB, /*DeleteDeadConditions = */ false,
                            /*TLI = */ nullptr, &DTU);
   return Changed;
nikic wrote:
> I think that something can go wrong here... Consider a case where we have a switch with branch weights, then we remove the first case (so that Changed=true in SwitchInstProfBranchWeightsWrapper), then we find that the second case is always true, such that this constant folding call will erase the switch, leaving behind a dangling reference in SwitchInstProfBranchWeightsWrapper, which will be accessed when the destructor runs at the end of the function.
Good catch!
ConstantFoldTerminator() can change SwitchInst on its own.

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list