================ @@ -2478,3 +2479,76 @@ PreservedAnalyses LowerTypeTestsPass::run(Module &M, return PreservedAnalyses::all(); return PreservedAnalyses::none(); } + +PreservedAnalyses SimplifyTypeTestsPass::run(Module &M, + ModuleAnalysisManager &AM) { + bool Changed = false; + // Figure out whether inlining has exposed a constant address to a lowered + // type test, and remove the test if so and the address is known to pass the + // test. Unfortunately this pass ends up needing to reverse engineer what + // LowerTypeTests did; this is currently inherent to the design of ThinLTO + // importing where LowerTypeTests needs to run at the start. + for (auto &GV : M.globals()) { + if (!GV.getName().starts_with("__typeid_") || + !GV.getName().ends_with("_global_addr")) + continue; + auto *MD = MDString::get(M.getContext(), + GV.getName().substr(9, GV.getName().size() - 21)); + auto MaySimplifyPtr = [&](Value *Ptr) { + if (auto *GV = dyn_cast<GlobalValue>(Ptr)) + if (auto *CFIGV = M.getNamedValue((GV->getName() + ".cfi").str())) + Ptr = CFIGV; + return isKnownTypeIdMember(MD, M.getDataLayout(), Ptr, 0); ---------------- teresajohnson wrote:
Are there cases where the GV will not have a ".cfi" extension? I notice the test has that extension. https://github.com/llvm/llvm-project/pull/141327 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits