1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

AtomicExpand: Don't crash on non-0 alloca

This now produces garbage on AMDGPU with a call to an nonexistent,
anonymous libcall but won't assert.

llvm-svn: 363022
This commit is contained in:
Matt Arsenault 2019-06-11 01:35:07 +00:00
parent e0a9e83b1e
commit 6a2dd0aca3
3 changed files with 44 additions and 2 deletions

View File

@ -1712,8 +1712,11 @@ bool AtomicExpand::expandAtomicOpToLibcall(
if (CASExpected) {
AllocaCASExpected = AllocaBuilder.CreateAlloca(CASExpected->getType());
AllocaCASExpected->setAlignment(AllocaAlignment);
unsigned AllocaAS = AllocaCASExpected->getType()->getPointerAddressSpace();
AllocaCASExpected_i8 =
Builder.CreateBitCast(AllocaCASExpected, Type::getInt8PtrTy(Ctx));
Builder.CreateBitCast(AllocaCASExpected,
Type::getInt8PtrTy(Ctx, AllocaAS));
Builder.CreateLifetimeStart(AllocaCASExpected_i8, SizeVal64);
Builder.CreateAlignedStore(CASExpected, AllocaCASExpected, AllocaAlignment);
Args.push_back(AllocaCASExpected_i8);
@ -1740,8 +1743,9 @@ bool AtomicExpand::expandAtomicOpToLibcall(
if (!CASExpected && HasResult && !UseSizedLibcall) {
AllocaResult = AllocaBuilder.CreateAlloca(I->getType());
AllocaResult->setAlignment(AllocaAlignment);
unsigned AllocaAS = AllocaResult->getType()->getPointerAddressSpace();
AllocaResult_i8 =
Builder.CreateBitCast(AllocaResult, Type::getInt8PtrTy(Ctx));
Builder.CreateBitCast(AllocaResult, Type::getInt8PtrTy(Ctx, AllocaAS));
Builder.CreateLifetimeStart(AllocaResult_i8, SizeVal64);
Args.push_back(AllocaResult_i8);
}

View File

@ -524,6 +524,7 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(const TargetMachine &TM,
setHasMultipleConditionRegisters(true);
setMinCmpXchgSizeInBits(32);
setSupportsUnalignedAtomics(false);
PredictableSelectIsExpensive = false;

View File

@ -0,0 +1,37 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -atomic-expand %s | FileCheck -check-prefix=GCN %s
; FIXME: This should not introduce a libcall, much less one to an
; anonymous function.
define i32 @atomic_load_global_align1(i32 addrspace(1)* %ptr) {
; GCN-LABEL: @atomic_load_global_align1(
; GCN-NEXT: [[TMP1:%.*]] = bitcast i32 addrspace(1)* [[PTR:%.*]] to i8 addrspace(1)*
; GCN-NEXT: [[TMP2:%.*]] = addrspacecast i8 addrspace(1)* [[TMP1]] to i8*
; GCN-NEXT: [[TMP3:%.*]] = alloca i32, align 4
; GCN-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP3]] to i8*
; GCN-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[TMP4]])
; GCN-NEXT: call void @0(i64 4, i8* [[TMP2]], i8* [[TMP4]], i32 5)
; GCN-NEXT: [[TMP5:%.*]] = load i32, i32* [[TMP3]], align 4
; GCN-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* [[TMP4]])
; GCN-NEXT: ret i32 [[TMP5]]
;
%val = load atomic i32, i32 addrspace(1)* %ptr seq_cst, align 1
ret i32 %val
}
define void @atomic_store_global_align1(i32 addrspace(1)* %ptr, i32 %val) {
; GCN-LABEL: @atomic_store_global_align1(
; GCN-NEXT: [[TMP1:%.*]] = bitcast i32 addrspace(1)* [[PTR:%.*]] to i8 addrspace(1)*
; GCN-NEXT: [[TMP2:%.*]] = addrspacecast i8 addrspace(1)* [[TMP1]] to i8*
; GCN-NEXT: [[TMP3:%.*]] = alloca i32, align 4
; GCN-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP3]] to i8*
; GCN-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* [[TMP4]])
; GCN-NEXT: store i32 [[VAL:%.*]], i32* [[TMP3]], align 4
; GCN-NEXT: call void @1(i64 4, i8* [[TMP2]], i8* [[TMP4]], i32 0)
; GCN-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* [[TMP4]])
; GCN-NEXT: ret void
;
store atomic i32 %val, i32 addrspace(1)* %ptr monotonic, align 1
ret void
}