diff options
author | Chris Lattner <sabre@nondot.org> | 2009-05-03 07:27:51 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-05-03 07:27:51 +0000 |
commit | 4df4ee0ff6f804e9d3dd478712e3b5b20cd3bf2f (patch) | |
tree | 720f189d430ecbbe197927fb84fa15afebe80a38 /lib/CodeGen/CGStmt.cpp | |
parent | 481fef9e25128fe87b19e41c48f771ee20c33cbe (diff) |
handle codegen of asms where a small input is tied to a large output.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70672 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 0a8cef2a67..f435f9cfb4 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -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; |