Index: llvm/tools/opt/opt.cpp =================================================================== --- llvm/tools/opt/opt.cpp +++ llvm/tools/opt/opt.cpp @@ -902,7 +902,7 @@ raw_ostream *OS = nullptr; // Write bitcode or assembly to the output as the last step... - if (!NoOutput && !AnalyzeOnly) { + if ((!NoOutput && !AnalyzeOnly) || RunTwice) { assert(Out); OS = &Out->os(); if (RunTwice) { @@ -950,13 +950,16 @@ "Writing the result of the second run to the specified output.\n" "To generate the one-run comparison binary, just run without\n" "the compile-twice option\n"; - Out->os() << BOS->str(); - Out->keep(); + if (!NoOutput && !AnalyzeOnly) { + Out->os() << BOS->str(); + Out->keep(); + } if (RemarksFile) RemarksFile->keep(); return 1; } - Out->os() << BOS->str(); + if (!NoOutput && !AnalyzeOnly) + Out->os() << BOS->str(); } if (DebugifyEach && !DebugifyExport.empty())