Skip to content

Commit b796a87

Browse files
ppogotovigcbot
authored andcommitted
Applied EmitScalarAtomics for 64 bit uniform atomics 3rd try
3rd try Extended EmitScalarAtomics function for atomics with 64 bit type
1 parent d8de9a4 commit b796a87

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12723,6 +12723,10 @@ void EmitPass::emitScalarAtomics(
1272312723
{
1272412724
case EATOMIC_IADD:
1272512725
case EATOMIC_SUB:
12726+
case EATOMIC_IADD64:
12727+
case EATOMIC_SUB64:
12728+
case EATOMIC_FADD64:
12729+
case EATOMIC_FSUB64:
1272612730
case EATOMIC_INC:
1272712731
case EATOMIC_DEC:
1272812732
case EATOMIC_FADD:
@@ -12768,13 +12772,18 @@ void EmitPass::emitScalarAtomics(
1276812772
{
1276912773
type = ISA_TYPE_F;
1277012774
}
12775+
else if (atomic_op == EATOMIC_FADD64 || atomic_op == EATOMIC_FSUB64)
12776+
{
12777+
type = ISA_TYPE_DF;
12778+
}
1277112779
else
1277212780
{
1277312781
type =
1277412782
bitWidth == 16 ? ISA_TYPE_W :
1277512783
bitWidth == 32 ? ISA_TYPE_D :
1277612784
ISA_TYPE_Q;
1277712785
}
12786+
1277812787
IGC_ASSERT_MESSAGE((bitWidth == 16) || (bitWidth == 32) || (bitWidth == 64), "invalid bitsize");
1277912788
if (atomic_op == EATOMIC_INC || atomic_op == EATOMIC_DEC)
1278012789
{
@@ -12968,7 +12977,7 @@ void EmitPass::emitScalarAtomics(
1296812977
m_encoder->Add(pSrcsArr[i], pSrcsArr[i], pReturnVal);
1296912978
m_encoder->Push();
1297012979

12971-
if (atomic_op == EATOMIC_IADD)
12980+
if (atomic_op == EATOMIC_IADD || atomic_op == EATOMIC_IADD64)
1297212981
{
1297312982
m_encoder->SetSrcModifier(1, EMOD_NEG);
1297412983
}
@@ -13098,14 +13107,32 @@ bool EmitPass::IsUniformAtomic(llvm::Instruction* pInst)
1309813107
{
1309913108
Function* F = pInst->getParent()->getParent();
1310013109
//We cannot optimize float atomics if the flag "unsafe-fp-math" was not passed.
13101-
if (id == GenISAIntrinsic::GenISA_floatatomicrawA64) {
13102-
if (pInst->getType()->getScalarSizeInBits() != 32) {
13110+
if (id == GenISAIntrinsic::GenISA_floatatomicrawA64)
13111+
{
13112+
if (!F->hasFnAttribute("unsafe-fp-math") || !(F->getFnAttribute("unsafe-fp-math").getValueAsString() == "true"))
13113+
{
1310313114
return false;
1310413115
}
13105-
if (!F->hasFnAttribute("unsafe-fp-math") || !(F->getFnAttribute("unsafe-fp-math").getValueAsString() == "true")) {
13116+
}
13117+
13118+
if (pInst->getType()->getScalarSizeInBits() == 64)
13119+
{
13120+
AtomicOp atomic_op = static_cast<AtomicOp>(llvm::cast<llvm::ConstantInt>(pInst->getOperand(3))->getZExtValue());
13121+
13122+
if ((atomic_op == EATOMIC_IADD64 || atomic_op == EATOMIC_SUB64) && m_currShader->m_Platform->hasInt64Add())
13123+
{
13124+
return true;
13125+
}
13126+
else if ((atomic_op == EATOMIC_FADD64 || atomic_op == EATOMIC_FSUB64) && m_currShader->m_Platform->hasFP64GlobalAtomicAdd())
13127+
{
13128+
return true;
13129+
}
13130+
else
13131+
{
1310613132
return false;
1310713133
}
1310813134
}
13135+
1310913136
if (IGC_IS_FLAG_ENABLED(DisableScalarAtomics) ||
1311013137
F->hasFnAttribute("KMPLOCK") ||
1311113138
m_currShader->m_DriverInfo->WASLMPointersDwordUnit())
@@ -13122,6 +13149,10 @@ bool EmitPass::IsUniformAtomic(llvm::Instruction* pInst)
1312213149

1312313150
bool isAtomicAdd =
1312413151
atomic_op == EATOMIC_IADD ||
13152+
atomic_op == EATOMIC_IADD64 ||
13153+
atomic_op == EATOMIC_SUB64 ||
13154+
atomic_op == EATOMIC_FADD64 ||
13155+
atomic_op == EATOMIC_FSUB64 ||
1312513156
atomic_op == EATOMIC_INC ||
1312613157
atomic_op == EATOMIC_SUB ||
1312713158
atomic_op == EATOMIC_DEC ||
@@ -13290,7 +13321,7 @@ void EmitPass::emitAtomicRaw(llvm::GenIntrinsicInst* pInsn)
1329013321
CVariable* pDstAddr = GetSymbol(pllDstAddr);
1329113322
// If DisableScalarAtomics regkey is enabled or DisableIGCOptimizations regkey is enabled then
1329213323
// don't enable scalar atomics, also do not enable for 64 bit
13293-
if (IsUniformAtomic(pInsn) && bitwidth != 64)
13324+
if (IsUniformAtomic(pInsn))
1329413325
{
1329513326
PointerType* PtrTy = dyn_cast<PointerType>(pllDstAddr->getType());
1329613327
bool isA64 = PtrTy && isA64Ptr(PtrTy, m_currShader->GetContext());

0 commit comments

Comments
 (0)