diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2297b27ffdc0..35578040d951 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -549,13 +549,15 @@ bool AsmPrinter::doInitialization(Module &M) {
   // alternative is duplicated code in each of the target asm printers that
   // use the directive, where it would need the same conditionalization
   // anyway.
-  if (Target.isOSBinFormatMachO() && Target.isOSDarwin()) {
-    Triple TVT(M.getDarwinTargetVariantTriple());
-    OutStreamer->emitVersionForTarget(
-        Target, M.getSDKVersion(),
-        M.getDarwinTargetVariantTriple().empty() ? nullptr : &TVT,
-        M.getDarwinTargetVariantSDKVersion());
+  if (MAI.useIntegratedAssembler()) {
+    if (Target.isOSBinFormatMachO() && Target.isOSDarwin()) {
+      Triple TVT(M.getDarwinTargetVariantTriple());
+      OutStreamer->emitVersionForTarget(
+          Target, M.getSDKVersion(),
+          M.getDarwinTargetVariantTriple().empty() ? nullptr : &TVT,
+          M.getDarwinTargetVariantSDKVersion());
+    }
   }

   // Allow the target to emit any magic that it wants at the start of the file.
