msl: Explain side-effect annotation in preserved loops

Bug: tint:2125, chromium:1513738
Change-Id: I63cdea2f461e8ed68c95e832de3285eb047485db
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/167763
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
index 4f90706..517885a 100644
--- a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
@@ -3034,8 +3034,28 @@
 void ASTPrinter::EmitLoopPreserver() {
     IncrementIndent();
     // This statement prevents the MSL compiler from erasing a loop during
-    // optimimzations.
+    // optimizations.  In the AIR dialiect of LLVM IR, WGSL loops should compile
+    // to a loop that contains an 'asm' call with a 'sideeffect' annotation.
+    //
+    // For example, compile a WGSL file with a trivial while(1) loop to 'a.metal',
+    // then compile that to AIR (LLVM IR dialect):
+    //
+    //    xcrun metal a.metal -S -o -
+    //
+    // The loop in the AIR should look something like this:
+    //
+    //    1: ...
+    //      br label %2
+    //
+    //    2:                                      ; preds = %1, %2
+    //      tail call void asm sideeffect "", ""() #1, !srcloc !27
+    //      br label %2, !llvm.loop !28
+    //
+    // It is important that the 'sideeffect' annotation exist. That tells the
+    // optimizer that the instruction has side effects invisible to the
+    // optimizer, and therefore the loop should not be eliminated.
     Line() << R"(__asm__("");)";
+
     DecrementIndent();
 }