diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -6313,7 +6313,7 @@ // epilogue. if (IsWin64) { for (unsigned I = 0, E = Ins.size(); I != E; ++I) { - if (Ins[I].Flags.isInReg()) { + if (Ins[I].Flags.isInReg() && Ins[I].Flags.isSRet()) { assert(!FuncInfo->getSRetReturnReg()); MVT PtrTy = getPointerTy(DAG.getDataLayout()); diff --git a/llvm/test/CodeGen/AArch64/arm64-windows-calls.ll b/llvm/test/CodeGen/AArch64/arm64-windows-calls.ll --- a/llvm/test/CodeGen/AArch64/arm64-windows-calls.ll +++ b/llvm/test/CodeGen/AArch64/arm64-windows-calls.ll @@ -176,3 +176,15 @@ ; CHECK: bl copy_notpod ; CHECK-NEXT: stp x0, x1, [{{.*}}] } + +; We shouldn't return the argument +; when it has only inreg attribute +define i64 @foobar(i64* inreg %0) { +; CHECK-LABEL: foobar: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: ldr x0, [x0] +; CHECK-NEXT: ret +entry: + %1 = load i64, i64* %0 + ret i64 %1 +}