diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -196,11 +196,14 @@ if (!PassConfig) return true; - if (!TargetPassConfig::willCompleteCodeGenPipeline()) - PM.add(createPrintMIRPass(Out)); - else if (addAsmPrinter(PM, Out, DwoOut, FileType, - MMIWP->getMMI().getContext())) - return true; + if (TargetPassConfig::willCompleteCodeGenPipeline()) { + if (addAsmPrinter(PM, Out, DwoOut, FileType, MMIWP->getMMI().getContext())) + return true; + } else { + // MIR printing is redundant with -filetype=null. + if (FileType != CGFT_Null) + PM.add(createPrintMIRPass(Out)); + } PM.add(createFreeMachineFunctionPass()); return false; diff --git a/llvm/test/tools/llc/filetype-null-stop-after.ll b/llvm/test/tools/llc/filetype-null-stop-after.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llc/filetype-null-stop-after.ll @@ -0,0 +1,3 @@ +; -stop-after would normally dump MIR, but with -filetype=null as well check +; there's no output at all. +; RUN: llc -filetype=null -stop-after=finalize-isel -o - %s | count 0