diff --git a/llvm/include/llvm/Transforms/Scalar/LowerMatrixIntrinsics.h b/llvm/include/llvm/Transforms/Scalar/LowerMatrixIntrinsics.h --- a/llvm/include/llvm/Transforms/Scalar/LowerMatrixIntrinsics.h +++ b/llvm/include/llvm/Transforms/Scalar/LowerMatrixIntrinsics.h @@ -16,7 +16,12 @@ #include "llvm/IR/PassManager.h" namespace llvm { -struct LowerMatrixIntrinsicsPass : PassInfoMixin { +class LowerMatrixIntrinsicsPass + : public PassInfoMixin { + bool Minimal; + +public: + LowerMatrixIntrinsicsPass(bool Minimal = false) : Minimal(Minimal) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); static bool isRequired() { return true; } }; diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1740,7 +1740,8 @@ /*InsertLifetimeIntrinsics=*/PTO.Coroutines)); if (EnableMatrix) - MPM.addPass(createModuleToFunctionPassAdaptor(LowerMatrixIntrinsicsPass())); + MPM.addPass( + createModuleToFunctionPassAdaptor(LowerMatrixIntrinsicsPass(true))); if (!LateLoopOptimizationsEPCallbacks.empty()) { LoopPassManager LPM(DebugLogging); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -236,6 +236,7 @@ FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass()) FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass()) FUNCTION_PASS("lower-matrix-intrinsics", LowerMatrixIntrinsicsPass()) +FUNCTION_PASS("lower-matrix-intrinsics-minimal", LowerMatrixIntrinsicsPass(true)) FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass()) FUNCTION_PASS("guard-widening", GuardWideningPass()) FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass()) diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -1937,16 +1937,25 @@ PreservedAnalyses LowerMatrixIntrinsicsPass::run(Function &F, FunctionAnalysisManager &AM) { auto &TTI = AM.getResult(F); - auto &ORE = AM.getResult(F); - auto &AA = AM.getResult(F); - auto &DT = AM.getResult(F); - auto &LI = AM.getResult(F); + OptimizationRemarkEmitter *ORE = nullptr; + AAResults *AA = nullptr; + DominatorTree *DT = nullptr; + LoopInfo *LI = nullptr; + + if (!Minimal) { + ORE = &AM.getResult(F); + AA = &AM.getResult(F); + DT = &AM.getResult(F); + LI = &AM.getResult(F); + } - LowerMatrixIntrinsics LMT(F, TTI, &AA, &DT, &LI, &ORE); + LowerMatrixIntrinsics LMT(F, TTI, AA, DT, LI, ORE); if (LMT.Visit()) { PreservedAnalyses PA; - PA.preserve(); - PA.preserve(); + if (!Minimal) { + PA.preserve(); + PA.preserve(); + } return PA; } return PreservedAnalyses::all(); diff --git a/llvm/test/Other/new-pm-O0-defaults.ll b/llvm/test/Other/new-pm-O0-defaults.ll --- a/llvm/test/Other/new-pm-O0-defaults.ll +++ b/llvm/test/Other/new-pm-O0-defaults.ll @@ -10,6 +10,9 @@ ; RUN: opt -disable-verify -debug-pass-manager \ ; RUN: -passes='default' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT +; RUN: opt -disable-verify -debug-pass-manager -enable-matrix \ +; RUN: -passes='default' -S %s 2>&1 \ +; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT,CHECK-MATRIX ; RUN: opt -disable-verify -debug-pass-manager \ ; RUN: -passes='thinlto-pre-link' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT,CHECK-PRE-LINK @@ -27,6 +30,8 @@ ; CHECK-DEFAULT-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DEFAULT-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-DEFAULT-NEXT: Running analysis: ProfileSummaryAnalysis +; CHECK-MATRIX-NEXT: Running pass: LowerMatrixIntrinsicsPass +; CHECK-MATRIX-NEXT: Running analysis: TargetIRAnalysis ; CHECK-PRE-LINK-NEXT: Running pass: CanonicalizeAliasesPass ; CHECK-PRE-LINK-NEXT: Running pass: NameAnonGlobalPass ; CHECK-THINLTO-NEXT: Running pass: Annotation2MetadataPass diff --git a/llvm/test/Transforms/LowerMatrixIntrinsics/multiply-minimal.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/multiply-minimal.ll --- a/llvm/test/Transforms/LowerMatrixIntrinsics/multiply-minimal.ll +++ b/llvm/test/Transforms/LowerMatrixIntrinsics/multiply-minimal.ll @@ -1,5 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -lower-matrix-intrinsics-minimal -fuse-matrix-tile-size=2 -matrix-allow-contract -force-fuse-matrix -instcombine -verify-dom-info %s -S | FileCheck %s +; RUN: opt -passes='lower-matrix-intrinsics-minimal,instcombine,verify' -fuse-matrix-tile-size=2 -matrix-allow-contract -force-fuse-matrix %s -S | FileCheck %s ; Test for the minimal version of the matrix lowering pass, which does not ; require DT or AA. Make sure no tiling is happening, even though it was