Skip to content

Commit 184a13d

Browse files
arsenmzmodem
authored andcommitted
AArch64/GlobalISel: Narrow stack passed argument access size
This fixes a verifier error in the testcase from bug 47619. The stack passed s3 value was widened to 4-bytes, and producing a 4-byte memory access with a < 1 byte result type. We need to either widen the result type or narrow the access size. This copies the code directly from the AMDGPU handling, which narrows the load size. I don't like that every target has to handle this, but this is currently broken on the 11 release branch and this is the simplest fix. This reverts commit 42bfa7c. (cherry picked from commit 6cb0d23)
1 parent 81eb1c1 commit 184a13d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ struct IncomingArgHandler : public CallLowering::ValueHandler {
8484
}
8585
}
8686

87-
void assignValueToAddress(Register ValVReg, Register Addr, uint64_t Size,
87+
void assignValueToAddress(Register ValVReg, Register Addr, uint64_t MemSize,
8888
MachinePointerInfo &MPO, CCValAssign &VA) override {
8989
MachineFunction &MF = MIRBuilder.getMF();
90+
91+
// The reported memory location may be wider than the value.
92+
const LLT RegTy = MRI.getType(ValVReg);
93+
MemSize = std::min(static_cast<uint64_t>(RegTy.getSizeInBytes()), MemSize);
94+
9095
auto MMO = MF.getMachineMemOperand(
91-
MPO, MachineMemOperand::MOLoad | MachineMemOperand::MOInvariant, Size,
96+
MPO, MachineMemOperand::MOLoad | MachineMemOperand::MOInvariant, MemSize,
9297
inferAlignFromPtrInfo(MF, MPO));
9398
MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
9499
}

llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-evt-bug47619.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2-
; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator %s -o - | FileCheck %s
2+
; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s
33

44
; Make sure the i3 %arg8 value is correctly handled. This was trying
55
; to use MVT for EVT values passed on the stack and asserting before
@@ -17,7 +17,7 @@ define i3 @bug47619(i64 %arg, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %a
1717
; CHECK: [[COPY6:%[0-9]+]]:_(s64) = COPY $x6
1818
; CHECK: [[COPY7:%[0-9]+]]:_(s64) = COPY $x7
1919
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
20-
; CHECK: [[LOAD:%[0-9]+]]:_(s3) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load 4 from %fixed-stack.0, align 16)
20+
; CHECK: [[LOAD:%[0-9]+]]:_(s3) = G_LOAD [[FRAME_INDEX]](p0) :: (invariant load 1 from %fixed-stack.0, align 16)
2121
; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[LOAD]](s3)
2222
; CHECK: $w0 = COPY [[ANYEXT]](s32)
2323
; CHECK: RET_ReallyLR implicit $w0

0 commit comments

Comments
 (0)