[PATCH] MS asm: Filter out fpsw clobbers

Reid Kleckner rnk at google.com
Thu Mar 6 14:24:38 PST 2014


Hi echristo,

When parsing MS inline assembly, we note that fpsw is an implicit def of
most x87 FP operations, and add it to the clobber list.  However, we
don't recognize fpsw as a gcc register name, and we assert.  Clang
always adds an fpsr clobber, which means the same thing to LLVM, so we
can just use that.

This test case was broken by my LLVM change r196939.

http://llvm-reviews.chandlerc.com/D2993

Files:
  lib/Parse/ParseStmt.cpp
  test/CodeGen/ms-inline-asm.c

Index: lib/Parse/ParseStmt.cpp
===================================================================
--- lib/Parse/ParseStmt.cpp
+++ lib/Parse/ParseStmt.cpp
@@ -2211,6 +2211,12 @@
                                Clobbers, MII, IP, Callback))
     return StmtError();
 
+  // Filter out "fpsw".  Clang doesn't accept it, and it always lists flags and
+  // fpsr as clobbers.
+  auto End = std::remove_if(Clobbers.begin(), Clobbers.end(),
+                            [&](const std::string &s) { return s == "fpsw"; });
+  Clobbers.erase(End, Clobbers.end());
+
   // Build the vector of clobber StringRefs.
   unsigned NumClobbers = Clobbers.size();
   ClobberRefs.resize(NumClobbers);
Index: test/CodeGen/ms-inline-asm.c
===================================================================
--- test/CodeGen/ms-inline-asm.c
+++ test/CodeGen/ms-inline-asm.c
@@ -460,3 +460,12 @@
   // CHECK: call void asm sideeffect inteldialect "mov eax, [eax] .4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
   // CHECK: call void asm sideeffect inteldialect "mov eax, fs:[$$0] .4", "~{eax},~{dirflag},~{fpsr},~{flags}"()
 }
+
+void t40(float a) {
+  int i;
+  __asm fld a
+  __asm fistp i
+  // CHECK-LABEL: define void @t40
+  // CHECK: call void asm sideeffect inteldialect "fld dword ptr $0", "*m,~{dirflag},~{fpsr},~{flags}"(float* {{.*}})
+  // CHECK: call void asm sideeffect inteldialect "fistp dword ptr $0", "=*m,~{dirflag},~{fpsr},~{flags}"(i32* {{.*}})
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2993.1.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140306/e4c3e453/attachment.bin>


More information about the cfe-commits mailing list