diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -437,6 +437,16 @@ } static bool shouldApply(Function &F, ProfileSummaryInfo& PSI) { + // If any of the basic blocks have address taken, we should skip this pass + // because the cloned blocks by this pass will not have address taken, and + // hence they may be optimized out by SimplifyCFG if they are targets of + // indirect branches. + bool HasBBAddressTaken = + llvm::any_of(F.getBasicBlockList(), + [](const BasicBlock &BB) { return BB.hasAddressTaken(); }); + if (HasBBAddressTaken) + return false; + if (ForceCHR) return true;