Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp.orig
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1048,7 +1048,7 @@ void AsmPrinter::emitFunctionHeader() {
       // created here, before the function body, so that .prefalign can
       // reference it; emitFunctionBody will emit the label at the function
       // end.
-      Align MinAlign = emitAlignment(MF->getAlignment(), &F);
+      Align MinAlign = emitTrapAlignment(MF->getAlignment(), &F);
       if (MinAlign < PrefAlign) {
         CurrentFnEnd = createTempSymbol("func_end");
         OutStreamer->emitPrefAlign(PrefAlign, *CurrentFnEnd,
@@ -1056,7 +1056,7 @@ void AsmPrinter::emitFunctionHeader() {
                                    getSubtargetInfo());
       }
     } else {
-      emitAlignment(PrefAlign, &F);
+      emitTrapAlignment(PrefAlign, &F);
     }
   }
 
@@ -3846,6 +3846,31 @@ Align AsmPrinter::emitAlignment(Align Alignment, const
 }
 
 //===----------------------------------------------------------------------===//
+/// emitTrapAlignment - Emit an alignment directive to the specified power of
+/// two boundary, but call emitTrapToAlignment to fill with Trap instructions
+/// if the Target implements emitTrapToAlignment. Returns the effective
+/// alignment that was emitted, like emitAlignment.
+Align AsmPrinter::emitTrapAlignment(Align Alignment, const GlobalObject *GV) const {
+  if (GV)
+    Alignment = getGVAlignment(GV, GV->getParent()->getDataLayout(), Alignment);
+
+  if (Alignment == Align(1)) return Alignment;   // 1-byte aligned: no need to emit alignment.
+
+  return Alignment;
+}
+
+//===----------------------------------------------------------------------===//
+/// emitTrapToAlignment - Emit an alignment directive to the specified power
+/// of two boundary. This default implementation calls EmitCodeAlignment on
+/// the OutStreamer, but can be overridden by Target implementations.
+void AsmPrinter::emitTrapToAlignment(Align Alignment) const {
+  if (Alignment == Align(1)) return;
+  OutStreamer->emitCodeAlignment(Alignment, getSubtargetInfo());
+}
+
+
+
+//===----------------------------------------------------------------------===//
 // Constant emission.
 //===----------------------------------------------------------------------===//
 
@@ -4785,10 +4810,18 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasi
   for (auto &Handler : Handlers)
     Handler->beginCodeAlignment(MBB);
 
+  bool isReachableViaFallthrough =
+    std::find(MBB.pred_begin(), MBB.pred_end(), MBB.getPrevNode()) !=
+      MBB.pred_end();
   // Emit an alignment directive for this block, if needed.
   const Align Alignment = MBB.getAlignment();
-  if (Alignment != Align(1))
-    emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment());
+  if (Alignment != Align(1)) {
+    if (isReachableViaFallthrough) {
+      emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment());
+    } else {
+      emitTrapAlignment(Alignment);
+    }
+  }
 
   // If the block has its address taken, emit any labels that were used to
   // reference the block.  It is possible that there is more than one label
