Skip to content

Commit 68dac67

Browse files
committed
Undef and poison
1 parent 1639578 commit 68dac67

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,18 +1998,31 @@ PtrParts SplitPtrStructs::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
19981998
Type *OffTy = ResTy->getElementType(1);
19991999
Value *ZeroOff = Constant::getNullValue(OffTy);
20002000

2001-
// Special case for null pointers, which can be created by address space
2002-
// propagation.
2001+
// Special case for null pointers, undef, and poison, which can be created by
2002+
// address space propagation.
20032003
auto *InConst = dyn_cast<Constant>(In);
20042004
if (InConst && InConst->isNullValue()) {
20052005
Value *NullRsrc = Constant::getNullValue(RsrcTy);
20062006
SplitUsers.insert(&I);
20072007
return {NullRsrc, ZeroOff};
20082008
}
2009+
if (isa<PoisonValue>(In)) {
2010+
Value *PoisonRsrc = PoisonValue::get(RsrcTy);
2011+
Value *PoisonOff = PoisonValue::get(OffTy);
2012+
SplitUsers.insert(&I);
2013+
return {PoisonRsrc, PoisonOff};
2014+
}
2015+
if (isa<UndefValue>(In)) {
2016+
Value *UndefRsrc = UndefValue::get(RsrcTy);
2017+
Value *UndefOff = UndefValue::get(OffTy);
2018+
SplitUsers.insert(&I);
2019+
return {UndefRsrc, UndefOff};
2020+
}
20092021

20102022
if (I.getSrcAddressSpace() != AMDGPUAS::BUFFER_RESOURCE)
2011-
report_fatal_error("Only buffer resources (addrspace 8) and null pointers "
2012-
"can be cast to buffer fat pointers (addrspace 7)");
2023+
report_fatal_error(
2024+
"only buffer resources (addrspace 8) and null/poison pointers can be "
2025+
"cast to buffer fat pointers (addrspace 7)");
20132026
SplitUsers.insert(&I);
20142027
return {In, ZeroOff};
20152028
}

llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,42 @@ define i1 @test_null(ptr addrspace(7) %p) {
364364
ret i1 %is.null
365365
}
366366

367+
define ptr addrspace(7) @addrspacecast_undef() {
368+
; CHECK-LABEL: define { ptr addrspace(8), i32 } @addrspacecast_undef
369+
; CHECK-SAME: () #[[ATTR0]] {
370+
; CHECK-NEXT: ret { ptr addrspace(8), i32 } undef
371+
;
372+
%ret = addrspacecast ptr undef to ptr addrspace(7)
373+
ret ptr addrspace(7) %ret
374+
}
375+
376+
define <2 x ptr addrspace(7)> @addrspacecast_undef_vec() {
377+
; CHECK-LABEL: define { <2 x ptr addrspace(8)>, <2 x i32> } @addrspacecast_undef_vec
378+
; CHECK-SAME: () #[[ATTR0]] {
379+
; CHECK-NEXT: ret { <2 x ptr addrspace(8)>, <2 x i32> } undef
380+
;
381+
%ret = addrspacecast <2 x ptr> undef to <2 x ptr addrspace(7)>
382+
ret <2 x ptr addrspace(7)> %ret
383+
}
384+
385+
define ptr addrspace(7) @addrspacecast_poison() {
386+
; CHECK-LABEL: define { ptr addrspace(8), i32 } @addrspacecast_poison
387+
; CHECK-SAME: () #[[ATTR0]] {
388+
; CHECK-NEXT: ret { ptr addrspace(8), i32 } poison
389+
;
390+
%ret = addrspacecast ptr poison to ptr addrspace(7)
391+
ret ptr addrspace(7) %ret
392+
}
393+
394+
define <2 x ptr addrspace(7)> @addrspacecast_poison_vec() {
395+
; CHECK-LABEL: define { <2 x ptr addrspace(8)>, <2 x i32> } @addrspacecast_poison_vec
396+
; CHECK-SAME: () #[[ATTR0]] {
397+
; CHECK-NEXT: ret { <2 x ptr addrspace(8)>, <2 x i32> } poison
398+
;
399+
%ret = addrspacecast <2 x ptr> poison to <2 x ptr addrspace(7)>
400+
ret <2 x ptr addrspace(7)> %ret
401+
}
402+
367403
declare ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1), i16, i32, i32)
368404

369405
define ptr addrspace(7) @make_buffer_rsrc(ptr addrspace(1) %buf, i16 %stride, i32 %numRecords, i32 %flags) {

0 commit comments

Comments
 (0)