@@ -8748,6 +8748,22 @@ void EmitPass::emitGEP(llvm::Instruction* I)
87488748void EmitPass::emitIntToPtr(llvm::IntToPtrInst* I2P)
87498749{
87508750 CVariable* src = GetSymbol(I2P->getOperand(0));
8751+ unsigned addrSpace = I2P->getAddressSpace();
8752+
8753+ MDNode* genericMD = I2P->getMetadata("generic.arithmetic");
8754+
8755+ // Check if tag needs to be added before emitting I2P
8756+ if (addrSpace == ADDRESS_SPACE_GENERIC && genericMD)
8757+ {
8758+ // If the target address space is generic and the var was used for pointer arithmetic
8759+ // the private/local tag must be added at this time.
8760+ ConstantAsMetadata* MD = cast<ConstantAsMetadata>(genericMD->getOperand(0));
8761+ unsigned srcAddrSpace = (unsigned)dyn_cast<ConstantInt>(MD->getValue())->getZExtValue();
8762+ CVariable* taggedSrc = createAddressSpaceTag(src, srcAddrSpace);
8763+ if (taggedSrc)
8764+ src = taggedSrc;
8765+ }
8766+
87518767 CVariable* IntVar = m_currShader->BitCast(src, GetUnsignedType(src->GetType()));
87528768 m_encoder->Cast(m_destination, IntVar);
87538769 m_encoder->Push();
@@ -9080,6 +9096,153 @@ void EmitPass::emitAddrSpaceCast(llvm::AddrSpaceCastInst* addrSpaceCast)
90809096 }
90819097}
90829098
9099+ CVariable* EmitPass::createAddressSpaceTag(CVariable* src, unsigned int addrSpace)
9100+ {
9101+ CVariable* taggedSrc = nullptr;
9102+ if (addrSpace == ADDRESS_SPACE_PRIVATE)
9103+ {
9104+ if (m_pCtx->m_hasEmu64BitInsts && m_currShader->m_Platform->hasNoFullI64Support())
9105+ {
9106+ if (m_currShader->GetContext()->getRegisterPointerSizeInBits(addrSpace) == 32)
9107+ {
9108+ // Add tag to high part
9109+ taggedSrc = m_currShader->BitCast(m_destination, ISA_TYPE_UD);
9110+ // Low:
9111+ m_encoder->SetDstRegion(2);
9112+ m_encoder->Copy(taggedSrc, src);
9113+ m_encoder->Push();
9114+ // High:
9115+ m_encoder->SetDstSubReg(1);
9116+ m_encoder->SetDstRegion(2);
9117+ m_encoder->Copy(taggedSrc, m_currShader->ImmToVariable(0x20000000, ISA_TYPE_UD));
9118+ m_encoder->Push();
9119+ }
9120+ else
9121+ {
9122+ // Src
9123+ CVariable* srcAlias = m_currShader->GetNewAlias(src, ISA_TYPE_UD, 0, 0);
9124+ CVariable* srcLow = m_currShader->GetNewVariable(
9125+ numLanes(m_currShader->m_SIMDSize),
9126+ ISA_TYPE_UD, EALIGN_GRF, m_destination->IsUniform(),
9127+ CName(src->getName(), "Lo"));
9128+ CVariable* srcHigh = m_currShader->GetNewVariable(
9129+ numLanes(m_currShader->m_SIMDSize),
9130+ ISA_TYPE_UD, EALIGN_GRF, m_destination->IsUniform(),
9131+ CName(src->getName(), "Hi"));
9132+
9133+ // Split Src into {Low, High}
9134+ // Low:
9135+ m_encoder->SetSrcSubReg(0, 0);
9136+ m_encoder->SetSrcRegion(0, 2, 1, 0);
9137+ m_encoder->Copy(srcLow, srcAlias);
9138+ m_encoder->Push();
9139+ // High:
9140+ m_encoder->SetSrcSubReg(0, 1);
9141+ m_encoder->SetSrcRegion(0, 2, 1, 0);
9142+ m_encoder->Copy(srcHigh, srcAlias);
9143+ m_encoder->Push();
9144+
9145+ // Add tag to high part
9146+ m_encoder->Or(srcHigh, srcHigh, m_currShader->ImmToVariable(0x20000000, ISA_TYPE_UD));
9147+ m_encoder->Push();
9148+
9149+ // Copy result to Dst
9150+ taggedSrc = m_currShader->BitCast(m_destination, ISA_TYPE_UD);
9151+ // Low:
9152+ m_encoder->SetDstRegion(2);
9153+ m_encoder->Copy(taggedSrc, srcLow);
9154+ m_encoder->Push();
9155+ // High:
9156+ m_encoder->SetDstSubReg(1);
9157+ m_encoder->SetDstRegion(2);
9158+ m_encoder->Copy(taggedSrc, srcHigh);
9159+ m_encoder->Push();
9160+ }
9161+ }
9162+ else
9163+ {
9164+ taggedSrc = m_currShader->GetNewVariable(
9165+ numLanes(m_currShader->m_SIMDSize),
9166+ ISA_TYPE_UQ, m_currShader->getGRFAlignment(),
9167+ m_destination->IsUniform(), CName::NONE);
9168+ m_encoder->Or(taggedSrc, src, m_currShader->ImmToVariable(1ULL << 61, ISA_TYPE_UQ));
9169+ m_encoder->Push();
9170+ }
9171+ }
9172+ else if (addrSpace == ADDRESS_SPACE_LOCAL)
9173+ {
9174+ if (m_pCtx->m_hasEmu64BitInsts && m_currShader->m_Platform->hasNoFullI64Support())
9175+ {
9176+ if (m_currShader->GetContext()->getRegisterPointerSizeInBits(addrSpace) == 32)
9177+ {
9178+ // Add tag to high part
9179+ taggedSrc = m_currShader->BitCast(m_destination, ISA_TYPE_UD);
9180+ // Low:
9181+ m_encoder->SetDstRegion(2);
9182+ m_encoder->Copy(taggedSrc, src);
9183+ m_encoder->Push();
9184+ // High:
9185+ m_encoder->SetDstSubReg(1);
9186+ m_encoder->SetDstRegion(2);
9187+ m_encoder->Copy(taggedSrc, m_currShader->ImmToVariable(0x40000000, ISA_TYPE_UD));
9188+ m_encoder->Push();
9189+ }
9190+ else
9191+ {
9192+ // Src
9193+ CVariable* srcAlias = m_currShader->GetNewAlias(src, ISA_TYPE_UD, 0, 0);
9194+ CVariable* srcLow = m_currShader->GetNewVariable(
9195+ numLanes(m_currShader->m_SIMDSize),
9196+ ISA_TYPE_UD, EALIGN_GRF, m_destination->IsUniform(),
9197+ CName(src->getName(), "Lo"));
9198+ CVariable* srcHigh = m_currShader->GetNewVariable(
9199+ numLanes(m_currShader->m_SIMDSize),
9200+ ISA_TYPE_UD, EALIGN_GRF, m_destination->IsUniform(),
9201+ CName(src->getName(), "Hi"));
9202+
9203+ // Split Src into {Low, High}
9204+ // Low:
9205+ m_encoder->SetSrcSubReg(0, 0);
9206+ m_encoder->SetSrcRegion(0, 2, 1, 0);
9207+ m_encoder->Copy(srcLow, srcAlias);
9208+ m_encoder->Push();
9209+ // High:
9210+ m_encoder->SetSrcSubReg(0, 1);
9211+ m_encoder->SetSrcRegion(0, 2, 1, 0);
9212+ m_encoder->Copy(srcHigh, srcAlias);
9213+ m_encoder->Push();
9214+
9215+ // Add tag to high part
9216+ m_encoder->Or(srcHigh, srcHigh, m_currShader->ImmToVariable(0x40000000, ISA_TYPE_UD));
9217+ m_encoder->Push();
9218+
9219+ // Copy result to Dst
9220+ taggedSrc = m_currShader->BitCast(m_destination, ISA_TYPE_UD);
9221+ // Low:
9222+ m_encoder->SetDstRegion(2);
9223+ m_encoder->Copy(taggedSrc, srcLow);
9224+ m_encoder->Push();
9225+ // High:
9226+ m_encoder->SetDstSubReg(1);
9227+ m_encoder->SetDstRegion(2);
9228+ m_encoder->Copy(taggedSrc, srcHigh);
9229+ m_encoder->Push();
9230+ }
9231+ }
9232+ else
9233+ {
9234+ taggedSrc = m_currShader->GetNewVariable(
9235+ numLanes(m_currShader->m_SIMDSize),
9236+ ISA_TYPE_UQ, m_currShader->getGRFAlignment(),
9237+ m_destination->IsUniform(),
9238+ CName::NONE);
9239+ m_encoder->Or(taggedSrc, src, m_currShader->ImmToVariable(1ULL << 62, ISA_TYPE_UQ));
9240+ m_encoder->Push();
9241+ }
9242+ }
9243+ return taggedSrc;
9244+ }
9245+
90839246void EmitPass::emitExtract(llvm::Instruction* inst)
90849247{
90859248 IGC_ASSERT(llvm::isa<llvm::ExtractElementInst>(inst));
0 commit comments