[llvm-branch-commits] [llvm] Add SimplifyTypeTests pass. (PR #141327)

Florian Mayer via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 28 10:18:11 PDT 2025


================
@@ -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(),
----------------
fmayer wrote:

I would just use `strlen("__typeid_")` and `strlen("_global_addr")`

https://github.com/llvm/llvm-project/pull/141327


More information about the llvm-branch-commits mailing list