]> granicus.if.org Git - clang/commitdiff
PR22560: Fix argument order for ARM _MoveToCoprocessor builtins.
authorBob Wilson <bob.wilson@apple.com>
Tue, 23 Jun 2015 21:10:15 +0000 (21:10 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 23 Jun 2015 21:10:15 +0000 (21:10 +0000)
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

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/arm-microsoft-intrinsics.c

index a14daac596f5dbf341cee66707edc39c262571f6..87def369c4f365665426f7f9224f50854e9d4f9d 100644 (file)
@@ -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();
 
index 5f19e5e7c87c97e4706e86919ad5689e79049e95..44782453a7a19e9bd4f3262187a8f325bb7199f5 100644 (file)
@@ -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'