From: Bob Wilson Date: Tue, 23 Jun 2015 21:10:15 +0000 (+0000) Subject: PR22560: Fix argument order for ARM _MoveToCoprocessor builtins. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=732f9bc1a0e91abf2314e3c1bbafe5541f0708f9;p=clang PR22560: Fix argument order for ARM _MoveToCoprocessor builtins. The Microsoft-extension _MoveToCoprocessor and _MoveToCoprocessor2 builtins take the register value to be moved as the first argument, but the corresponding mcr and mcr2 LLVM intrinsics expect that value to be the third argument. Handle this as a special case, while still leaving those intrinsics as generic MSBuiltins. I considered the alternative of handling these in EmitARMBuiltinExpr, but that does not work well for the follow-up change that I'm going to make to improve the error handling for PR22560 -- we need the GetBuiltinType() checks for ICEArguments, and the ARM version of that code is only used for Neon intrinsics where the last argument is special and not checked in the normal way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240462 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index a14daac596..87def369c4 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -1831,6 +1831,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, Args.push_back(ArgValue); } + // The ARM _MoveToCoprocessor builtins put the input register value as + // the first argument, but the LLVM intrinsic expects it as the third one. + if (BuiltinID == ARM::BI_MoveToCoprocessor || + BuiltinID == ARM::BI_MoveToCoprocessor2) { + return RValue::get(Builder.CreateCall(F, {Args[1], Args[2], Args[0], + Args[3], Args[4], Args[5]})); + } + Value *V = Builder.CreateCall(F, Args); QualType BuiltinRetType = E->getType(); diff --git a/test/CodeGen/arm-microsoft-intrinsics.c b/test/CodeGen/arm-microsoft-intrinsics.c index 5f19e5e7c8..44782453a7 100644 --- a/test/CodeGen/arm-microsoft-intrinsics.c +++ b/test/CodeGen/arm-microsoft-intrinsics.c @@ -47,17 +47,17 @@ unsigned int check_MoveFromCoprocessor2(void) { // CHECK-MSVC: @llvm.arm.mrc2(i32 0, i32 0, i32 0, i32 0, i32 0) // CHECK-EABI: error: implicit declaration of function '_MoveFromCoprocessor2' -void check_MoveToCoprocessor(void) { - _MoveToCoprocessor(0, 0, 0, 0, 0, 0); +void check_MoveToCoprocessor(unsigned int value) { + _MoveToCoprocessor(value, 10, 7, 1, 0, 0); } -// CHECK-MSVC: @llvm.arm.mcr(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) +// CHECK-MSVC: @llvm.arm.mcr(i32 10, i32 7, i32 %0, i32 1, i32 0, i32 0) // CHECK-EABI: error: implicit declaration of function '_MoveToCoprocessor' -void check_MoveToCoprocessor2(void) { - _MoveToCoprocessor2(0, 0, 0, 0, 0, 0); +void check_MoveToCoprocessor2(unsigned int value) { + _MoveToCoprocessor2(value, 10, 7, 1, 0, 0); } -// CHECK-MSVC: @llvm.arm.mcr2(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0) +// CHECK-MSVC: @llvm.arm.mcr2(i32 10, i32 7, i32 %0, i32 1, i32 0, i32 0) // CHECK-EABI: error: implicit declaration of function '_MoveToCoprocessor2'