mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-19 01:48:34 +00:00
[ARM] GlobalISel: Fix extended stack operands
Fix a crash when trying to extend a value passed as a sign- or zero-extended stack parameter. The cause of the crash was that we were setting the size of the loaded value to 32 bits, and then tyring to extend again to 32 bits. This patch addresses the issue by also introducing a G_TRUNC after the load. This will leave the unused bits to their original values set by the caller, while being consistent about the types. For values that are not extended, we just use a smaller load. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301531 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9ec7e0297d
commit
6790813007
@ -245,12 +245,21 @@ struct IncomingValueHandler : public CallLowering::ValueHandler {
|
||||
// that's what we should load.
|
||||
Size = 4;
|
||||
assert(MRI.getType(ValVReg).isScalar() && "Only scalars supported atm");
|
||||
MRI.setType(ValVReg, LLT::scalar(32));
|
||||
}
|
||||
|
||||
auto LoadVReg = MRI.createGenericVirtualRegister(LLT::scalar(32));
|
||||
buildLoad(LoadVReg, Addr, Size, /* Alignment */ 0, MPO);
|
||||
MIRBuilder.buildTrunc(ValVReg, LoadVReg);
|
||||
} else {
|
||||
// If the value is not extended, a simple load will suffice.
|
||||
buildLoad(ValVReg, Addr, Size, /* Alignment */ 0, MPO);
|
||||
}
|
||||
}
|
||||
|
||||
void buildLoad(unsigned Val, unsigned Addr, uint64_t Size, unsigned Alignment,
|
||||
MachinePointerInfo &MPO) {
|
||||
auto MMO = MIRBuilder.getMF().getMachineMemOperand(
|
||||
MPO, MachineMemOperand::MOLoad, Size, /* Alignment */ 0);
|
||||
MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
|
||||
MPO, MachineMemOperand::MOLoad, Size, Alignment);
|
||||
MIRBuilder.buildLoad(Val, Addr, *MMO);
|
||||
}
|
||||
|
||||
void assignValueToReg(unsigned ValVReg, unsigned PhysReg,
|
||||
|
@ -148,8 +148,9 @@ define i16 @test_stack_args_signext(i32 %p0, i16 %p1, i8 %p2, i1 %p3,
|
||||
; CHECK: liveins: %r0, %r1, %r2, %r3
|
||||
; CHECK: [[VREGP1:%[0-9]+]]{{.*}} = COPY %r1
|
||||
; CHECK: [[FIP5:%[0-9]+]]{{.*}} = G_FRAME_INDEX %fixed-stack.[[P5]]
|
||||
; CHECK: [[VREGP5:%[0-9]+]]{{.*}} = G_LOAD [[FIP5]](p0)
|
||||
; CHECK: [[SUM:%[0-9]+]]{{.*}} = G_ADD [[VREGP1]], [[VREGP5]]
|
||||
; CHECK: [[VREGP5EXT:%[0-9]+]](s32) = G_LOAD [[FIP5]](p0)
|
||||
; CHECK: [[VREGP5:%[0-9]+]](s16) = G_TRUNC [[VREGP5EXT]]
|
||||
; CHECK: [[SUM:%[0-9]+]](s16) = G_ADD [[VREGP1]], [[VREGP5]]
|
||||
; CHECK: %r0 = COPY [[SUM]]
|
||||
; CHECK: BX_RET 14, _, implicit %r0
|
||||
entry:
|
||||
@ -166,8 +167,9 @@ define i8 @test_stack_args_zeroext(i32 %p0, i16 %p1, i8 %p2, i1 %p3,
|
||||
; CHECK: liveins: %r0, %r1, %r2, %r3
|
||||
; CHECK: [[VREGP2:%[0-9]+]]{{.*}} = COPY %r2
|
||||
; CHECK: [[FIP4:%[0-9]+]]{{.*}} = G_FRAME_INDEX %fixed-stack.[[P4]]
|
||||
; CHECK: [[VREGP4:%[0-9]+]]{{.*}} = G_LOAD [[FIP4]](p0)
|
||||
; CHECK: [[SUM:%[0-9]+]]{{.*}} = G_ADD [[VREGP2]], [[VREGP4]]
|
||||
; CHECK: [[VREGP4EXT:%[0-9]+]](s32) = G_LOAD [[FIP4]](p0)
|
||||
; CHECK: [[VREGP4:%[0-9]+]](s8) = G_TRUNC [[VREGP4EXT]]
|
||||
; CHECK: [[SUM:%[0-9]+]](s8) = G_ADD [[VREGP2]], [[VREGP4]]
|
||||
; CHECK: %r0 = COPY [[SUM]]
|
||||
; CHECK: BX_RET 14, _, implicit %r0
|
||||
entry:
|
||||
@ -175,6 +177,41 @@ entry:
|
||||
ret i8 %sum
|
||||
}
|
||||
|
||||
define i8 @test_stack_args_noext(i32 %p0, i16 %p1, i8 %p2, i1 %p3,
|
||||
i8 %p4, i16 %p5) {
|
||||
; CHECK-LABEL: name: test_stack_args_noext
|
||||
; CHECK: fixedStack:
|
||||
; CHECK-DAG: id: [[P4:[0-9]]]{{.*}}offset: 0{{.*}}size: 1
|
||||
; CHECK-DAG: id: [[P5:[0-9]]]{{.*}}offset: 4{{.*}}size: 2
|
||||
; CHECK: liveins: %r0, %r1, %r2, %r3
|
||||
; CHECK: [[VREGP2:%[0-9]+]]{{.*}} = COPY %r2
|
||||
; CHECK: [[FIP4:%[0-9]+]]{{.*}} = G_FRAME_INDEX %fixed-stack.[[P4]]
|
||||
; CHECK: [[VREGP4:%[0-9]+]](s8) = G_LOAD [[FIP4]](p0)
|
||||
; CHECK: [[SUM:%[0-9]+]](s8) = G_ADD [[VREGP2]], [[VREGP4]]
|
||||
; CHECK: %r0 = COPY [[SUM]]
|
||||
; CHECK: BX_RET 14, _, implicit %r0
|
||||
entry:
|
||||
%sum = add i8 %p2, %p4
|
||||
ret i8 %sum
|
||||
}
|
||||
|
||||
define zeroext i16 @test_stack_args_extend_the_extended(i32 %p0, i16 %p1, i8 %p2, i1 %p3,
|
||||
i8 signext %p4, i16 signext %p5) {
|
||||
; CHECK-LABEL: name: test_stack_args_extend_the_extended
|
||||
; CHECK: fixedStack:
|
||||
; CHECK-DAG: id: [[P4:[0-9]]]{{.*}}offset: 0{{.*}}size: 1
|
||||
; CHECK-DAG: id: [[P5:[0-9]]]{{.*}}offset: 4{{.*}}size: 2
|
||||
; CHECK: liveins: %r0, %r1, %r2, %r3
|
||||
; CHECK: [[FIP5:%[0-9]+]]{{.*}} = G_FRAME_INDEX %fixed-stack.[[P5]]
|
||||
; CHECK: [[VREGP5SEXT:%[0-9]+]](s32) = G_LOAD [[FIP5]](p0)
|
||||
; CHECK: [[VREGP5:%[0-9]+]](s16) = G_TRUNC [[VREGP5SEXT]]
|
||||
; CHECK: [[VREGP5ZEXT:%[0-9]+]](s32) = G_ZEXT [[VREGP5]]
|
||||
; CHECK: %r0 = COPY [[VREGP5ZEXT]]
|
||||
; CHECK: BX_RET 14, _, implicit %r0
|
||||
entry:
|
||||
ret i16 %p5
|
||||
}
|
||||
|
||||
define i16 @test_ptr_arg(i16* %p) {
|
||||
; CHECK-LABEL: name: test_ptr_arg
|
||||
; CHECK: liveins: %r0
|
||||
|
@ -197,6 +197,17 @@ entry:
|
||||
ret i8 %sum
|
||||
}
|
||||
|
||||
define i8 @test_stack_args_noext(i32 %p0, i16 %p1, i8 %p2, i1 %p3, i8 %p4) {
|
||||
; CHECK-LABEL: test_stack_args_noext:
|
||||
; CHECK: mov [[P4ADDR:r[0-9]+]], sp
|
||||
; CHECK: ldrb [[P4:r[0-9]+]], {{.*}}[[P4ADDR]]
|
||||
; CHECK: add r0, r2, [[P4]]
|
||||
; CHECK: bx lr
|
||||
entry:
|
||||
%sum = add i8 %p2, %p4
|
||||
ret i8 %sum
|
||||
}
|
||||
|
||||
define i32 @test_ptr_arg_in_reg(i32* %p) {
|
||||
; CHECK-LABEL: test_ptr_arg_in_reg:
|
||||
; CHECK: ldr r0, [r0]
|
||||
|
Loading…
Reference in New Issue
Block a user