Skip to content

Commit f1e4959

Browse files
mmereckigfxbot
authored andcommitted
Fixes PromoteResourceToDirectAS pass to correclty promote atomic instructions, adds support for typed atomics
Change-Id: Ie4897e0eb9eb00e516d601ecddf32d7775f136c0
1 parent b952828 commit f1e4959

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

IGC/Compiler/PromoteResourceToDirectAS.cpp

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ Value* GetBufferOperand(Instruction* inst)
111111
case GenISAIntrinsic::GenISA_ldrawvector_indexed:
112112
case GenISAIntrinsic::GenISA_storeraw_indexed:
113113
case GenISAIntrinsic::GenISA_ldraw_indexed:
114-
pBuffer = intr->getOperand(0);
115-
break;
116114
case GenISAIntrinsic::GenISA_intatomicraw:
115+
case GenISAIntrinsic::GenISA_intatomictyped:
116+
case GenISAIntrinsic::GenISA_icmpxchgatomictyped:
117117
case GenISAIntrinsic::GenISA_floatatomicraw:
118118
case GenISAIntrinsic::GenISA_icmpxchgatomicraw:
119119
case GenISAIntrinsic::GenISA_fcmpxchgatomicraw:
120+
pBuffer = intr->getOperand(0);
121+
break;
120122
case GenISAIntrinsic::GenISA_intatomicrawA64:
121123
case GenISAIntrinsic::GenISA_floatatomicrawA64:
122124
case GenISAIntrinsic::GenISA_icmpxchgatomicrawA64:
@@ -151,6 +153,8 @@ Type* GetBufferAccessType(Instruction *inst)
151153
case GenISAIntrinsic::GenISA_ldrawvector_indexed:
152154
case GenISAIntrinsic::GenISA_ldraw_indexed:
153155
case GenISAIntrinsic::GenISA_intatomicraw:
156+
case GenISAIntrinsic::GenISA_intatomictyped:
157+
case GenISAIntrinsic::GenISA_icmpxchgatomictyped:
154158
case GenISAIntrinsic::GenISA_floatatomicraw:
155159
case GenISAIntrinsic::GenISA_icmpxchgatomicraw:
156160
case GenISAIntrinsic::GenISA_fcmpxchgatomicraw:
@@ -531,6 +535,8 @@ void PromoteResourceToDirectAS::PromoteBufferToDirectAS(Instruction* inst, Value
531535
{
532536
case GenISAIntrinsic::GenISA_intatomicraw:
533537
case GenISAIntrinsic::GenISA_floatatomicraw:
538+
case GenISAIntrinsic::GenISA_intatomictyped:
539+
case GenISAIntrinsic::GenISA_icmpxchgatomictyped:
534540
case GenISAIntrinsic::GenISA_icmpxchgatomicraw:
535541
case GenISAIntrinsic::GenISA_fcmpxchgatomicraw:
536542
is64BitPtr = false;
@@ -569,14 +575,14 @@ void PromoteResourceToDirectAS::PromoteBufferToDirectAS(Instruction* inst, Value
569575
}
570576
else
571577
{
578+
bufferAddress = pIntr->getArgOperand(1);
572579
if (!isa<ConstantPointerNull>(pBuffer))
573580
{
581+
assert(isa<ConstantInt>(bufferAddress) && cast<ConstantInt>(bufferAddress)->getZExtValue() == 0);
582+
assert(pIntr->getIntrinsicID() != GenISAIntrinsic::GenISA_intatomictyped &&
583+
pIntr->getIntrinsicID() != GenISAIntrinsic::GenISA_icmpxchgatomictyped);
574584
bufferAddress = builder.CreatePtrToInt(pBuffer, builder.getInt32Ty());
575585
}
576-
else
577-
{
578-
bufferAddress = builder.getInt32(0);
579-
}
580586
}
581587

582588
args.push_back(sourcePointer);
@@ -613,30 +619,30 @@ void PromoteResourceToDirectAS::PromoteBufferToDirectAS(Instruction* inst, Value
613619

614620
void PromoteResourceToDirectAS::GetAccessInstToSrcPointerMap(Instruction* inst, Value* resourcePtr)
615621
{
616-
unsigned addrSpace = resourcePtr->getType()->getPointerAddressSpace();
622+
unsigned addrSpace = resourcePtr->getType()->getPointerAddressSpace();
617623

618-
if (addrSpace != 1 && addrSpace != 2)
619-
{
620-
// Only try to promote stateless buffer pointers ( as(1) or as(2) )
624+
if (addrSpace != 1 && addrSpace != 2)
625+
{
626+
// Only try to promote stateless buffer pointers ( as(1) or as(2) )
621627
return;
622-
}
628+
}
623629

624-
if (!isa<LoadInst>(inst) && !isa<StoreInst>(inst))
625-
{
626-
// Do we need to support other instructions besides load/store?
627-
return;
628-
}
630+
if (!isa<LoadInst>(inst) && !isa<StoreInst>(inst))
631+
{
632+
// Do we need to support other instructions besides load/store?
633+
return;
634+
}
629635

630-
Value* srcPtr = IGC::TracePointerSource(resourcePtr);
636+
Value* srcPtr = IGC::TracePointerSource(resourcePtr);
631637

632-
if (!srcPtr ||
633-
!srcPtr->getType()->isPointerTy() ||
634-
!isa<Argument>(srcPtr))
635-
{
636-
// Cannot trace the resource pointer back to it's source, cannot promote
638+
if (!srcPtr ||
639+
!srcPtr->getType()->isPointerTy() ||
640+
!isa<Argument>(srcPtr))
641+
{
642+
// Cannot trace the resource pointer back to it's source, cannot promote
637643
assert(0 && "Stateless buffer pointer not tracable, cannot promote stateless to bindless");
638-
return;
639-
}
644+
return;
645+
}
640646

641647
m_AccessToSrcPtrMap[inst] = srcPtr;
642648
return;
@@ -720,11 +726,11 @@ void PromoteResourceToDirectAS::visitInstruction(Instruction &I)
720726
if (isStatelessToBindlessPromotion(m_pCodeGenContext))
721727
{
722728
GetAccessInstToSrcPointerMap(&I, bufptr);
723-
}
724-
else
725-
{
726-
PromoteBufferToDirectAS(&I, bufptr);
727-
}
729+
}
730+
else
731+
{
732+
PromoteBufferToDirectAS(&I, bufptr);
733+
}
728734
resourceAccessed = true;
729735
}
730736
}

0 commit comments

Comments
 (0)