[llvm] ed8409d - [ObjC][ARC] Fix target register for call expanded from CALL_RVMARKER on Windows

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 09:50:52 PDT 2022


Author: Stefan Gränitz
Date: 2022-09-27T18:49:40+02:00
New Revision: ed8409dfa0a92d80c021f13ca271737492522cc7

URL: https://github.com/llvm/llvm-project/commit/ed8409dfa0a92d80c021f13ca271737492522cc7
DIFF: https://github.com/llvm/llvm-project/commit/ed8409dfa0a92d80c021f13ca271737492522cc7.diff

LOG: [ObjC][ARC] Fix target register for call expanded from CALL_RVMARKER on Windows

Fix regression https://github.com/llvm/llvm-project/issues/56952 for Clang CodeGen on Windows. In the Windows ABI the instruction sequence that is expanded from CALL_RVMARKER should use RCX as target register and not RDI.

Reviewed By: rnk, fhahn

Differential Revision: https://reviews.llvm.org/D134441

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ExpandPseudo.cpp
    llvm/test/CodeGen/X86/call-rv-marker.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ExpandPseudo.cpp b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
index 1dd7f285ab74f..6ad61b256ba8c 100644
--- a/llvm/lib/Target/X86/X86ExpandPseudo.cpp
+++ b/llvm/lib/Target/X86/X86ExpandPseudo.cpp
@@ -224,9 +224,11 @@ void X86ExpandPseudo::expandCALL_RVMARKER(MachineBasicBlock &MBB,
   // Emit marker "movq %rax, %rdi".  %rdi is not callee-saved, so it cannot be
   // live across the earlier call. The call to the ObjC runtime function returns
   // the first argument, so the value of %rax is unchanged after the ObjC
-  // runtime call.
+  // runtime call. On Windows targets, the runtime call follows the regular
+  // x64 calling convention and expects the first argument in %rcx.
+  auto TargetReg = STI->getTargetTriple().isOSWindows() ? X86::RCX : X86::RDI;
   auto *Marker = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(X86::MOV64rr))
-                     .addReg(X86::RDI, RegState::Define)
+                     .addReg(TargetReg, RegState::Define)
                      .addReg(X86::RAX)
                      .getInstr();
   if (MI.shouldUpdateCallSiteInfo())

diff  --git a/llvm/test/CodeGen/X86/call-rv-marker.ll b/llvm/test/CodeGen/X86/call-rv-marker.ll
index 1cf56d9dc9f87..6ce7430b52c71 100644
--- a/llvm/test/CodeGen/X86/call-rv-marker.ll
+++ b/llvm/test/CodeGen/X86/call-rv-marker.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=x86_64-apple-macosx -verify-machineinstrs -o - %s | FileCheck --check-prefix=CHECK %s
+; RUN: llc -mtriple=x86_64-windows-msvc -verify-machineinstrs -o - %s | FileCheck --check-prefix=WINABI %s
 
 ; TODO: support marker generation with GlobalISel
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
@@ -33,6 +34,12 @@ define ptr @rv_marker_1_retain() {
 ; CHECK-NEXT:    popq    %rcx
 ; CHECK-NEXT:    retq
 ;
+; WINABI-LABEL: rv_marker_1_retain:
+; WINABI:        callq   foo1
+; WINABI-NEXT:   movq    %rax, %rcx
+; WINABI-NEXT:   callq   objc_retainAutoreleasedReturnValue
+; WINABI-NEXT:   nop
+;
 entry:
   %call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
   ret ptr %call


        


More information about the llvm-commits mailing list