Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -523,6 +523,12 @@ if (RunPartialInlining) MPM.add(createPartialInliningPass()); + if (ImportSummary) { + // Run this pass after inlining as it creates more opportunities to + // eliminate type checks. + MPM.add(createLowerTypeTestsPass(nullptr, ImportSummary)); + } + if (OptLevel > 1 && !PrepareForLTO && !PrepareForThinLTO) // Remove avail extern fns and globals definitions if we aren't // compiling an object file for later LTO. For LTO we want to preserve @@ -877,9 +883,9 @@ PM.add(createVerifierPass()); if (ImportSummary) { - // These passes import type identifier resolutions for whole-program - // devirtualization and CFI. They must run early because other passes may - // disturb the specific instruction patterns that these passes look for, + // This pass imports type identifier resolutions for whole-program + // devirtualization. It must run early because other passes may + // disturb the specific instruction patterns that this pass looks for, // creating dependencies on resolutions that may not appear in the summary. // // For example, GVN may transform the pattern assume(type.test) appearing in @@ -890,7 +896,6 @@ // Also, WPD has access to more precise information than ICP and can // devirtualize more effectively, so it should operate on the IR first. PM.add(createWholeProgramDevirtPass(nullptr, ImportSummary)); - PM.add(createLowerTypeTestsPass(nullptr, ImportSummary)); } populateModulePassManager(PM);