[llvm-commits] patch: Lower glibc's x86 bswap_32() inline asm

Sami Liedes sliedes at cc.hut.fi
Tue May 26 18:29:39 PDT 2009


This patch adds code in X86TargetAsmInfo::ExpandInlineAsm() to
recognize glibc's bswap_32() inline asm for x86 <i486 target and lower
it to llvm.bswap.i32.

	Sami


Index: lib/Target/X86/X86TargetAsmInfo.cpp
===================================================================
--- lib/Target/X86/X86TargetAsmInfo.cpp	(revision 72442)
+++ lib/Target/X86/X86TargetAsmInfo.cpp	(working copy)
@@ -402,7 +402,7 @@
 
   // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
   std::vector<std::string> AsmPieces;
-  SplitString(AsmStr, AsmPieces, "\n");  // ; as separator?
+  SplitString(AsmStr, AsmPieces, "\n;");
 
   switch (AsmPieces.size()) {
   default: return false;
@@ -452,6 +452,27 @@
         }
       }
     }
+    // rorw $$8, ${0:w};rorl $$16, $0;rorw $$8, ${0:w}  -->  llvm.bswap.i32
+    // (from Linux <bits/byteswap.h>)
+    if (CI->getType() == Type::Int32Ty &&
+	IA->getConstraintString() == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") {
+      std::vector<std::string> Words;
+      SplitString(AsmPieces[0], Words, " \t");
+      if (Words.size() == 3 && Words[0] == "rorw" && Words[1] == "$$8," &&
+	  Words[2] == "${0:w}") {
+        Words.clear();
+        SplitString(AsmPieces[1], Words, " \t");
+        if (Words.size() == 3 && Words[0] == "rorl" && Words[1] == "$$16," &&
+	    Words[2] == "$0") {
+          Words.clear();
+          SplitString(AsmPieces[2], Words, " \t");
+          if (Words.size() == 3 && Words[0] == "rorw" && Words[1] == "$$8," &&
+              Words[2] == "${0:w}") {
+            return LowerToBSwap(CI);
+          }
+        }
+      }
+    }
     break;
   }
   return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090527/08a4d5bc/attachment.sig>


More information about the llvm-commits mailing list