]> granicus.if.org Git - clang/commitdiff
handle codegen of asms where a small input is tied to a large output.
authorChris Lattner <sabre@nondot.org>
Sun, 3 May 2009 07:27:51 +0000 (07:27 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 3 May 2009 07:27:51 +0000 (07:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70672 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
test/CodeGen/asm.c

index 0a8cef2a674539da9afceeb54e50a24764119c9b..f435f9cfb402fabeb2c8f2e734ad34feda68bb60 100644 (file)
@@ -877,6 +877,28 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
     llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, Constraints);
     
+    // If this input argument is tied to a larger output result, extend the
+    // input to be the same size as the output.  The LLVM backend wants to see
+    // the input and output of a matching constraint be the same size.  Note
+    // that GCC does not define what the top bits are here.  We use zext because
+    // that is usually cheaper, but LLVM IR should really get an anyext someday.
+    if (Info.hasTiedOperand()) {
+      unsigned Output = Info.getTiedOperand();
+      QualType OutputTy = S.getOutputExpr(Output)->getType();
+      QualType InputTy = InputExpr->getType();
+      
+      if (getContext().getTypeSize(OutputTy) >
+          getContext().getTypeSize(InputTy)) {
+        // Use ptrtoint as appropriate so that we can do our extension.
+        if (isa<llvm::PointerType>(Arg->getType()))
+          Arg = Builder.CreatePtrToInt(Arg,
+                                      llvm::IntegerType::get(LLVMPointerWidth));
+        unsigned OutputSize = (unsigned)getContext().getTypeSize(OutputTy);
+        Arg = Builder.CreateZExt(Arg, llvm::IntegerType::get(OutputSize));
+      }
+    }
+    
+    
     ArgTypes.push_back(Arg->getType());
     Args.push_back(Arg);
     Constraints += InputConstraint;
index abe91519ed17d3d5b04555606e1b0b09daaa46dc..757a2740a7d082eebb3148f4f68dbd493094551e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm %s -o %t -arch=i386 &&
+c// RUN: clang-cc -emit-llvm %s -o %t -arch=i386 &&
 void t1(int len) {
   __asm__ volatile("" : "=&r"(len), "+&r"(len));
 }
@@ -49,3 +49,13 @@ unsigned t9(unsigned int a) {
 void t10(int r) {
   __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0)));
 }         
+
+
+// PR3373
+unsigned t11(signed char input) {
+  unsigned  output;
+  __asm__("xyz"
+          : "=a" (output)
+          : "0" (input));
+  return output;
+}