@@ -273,9 +273,9 @@ static bool DefReachUseWithinLevel(llvm::Value* def, const llvm::Instruction* us
273273 return false;
274274}
275275
276- bool EmitPass::IsNoMaskAllowed(SDAG& sdag )
276+ bool EmitPass::IsNoMaskAllowed(Instruction* inst )
277277{
278- if (auto* I = dyn_cast<LoadInst>(sdag.m_root ))
278+ if (auto* I = dyn_cast<LoadInst>(inst ))
279279 {
280280 if (IGC_IS_FLAG_ENABLED(UseVMaskPredicateForLoads) && shouldGenerateLSC(I))
281281 return true;
@@ -290,6 +290,15 @@ bool EmitPass::IsNoMaskAllowed(SDAG& sdag)
290290 return true;
291291}
292292
293+ bool EmitPass::IsSubspanDestination(Instruction* inst)
294+ {
295+ return m_pattern->IsSubspanUse(inst) && IsNoMaskAllowed(inst) &&
296+ (!m_pattern->IsSourceOfSample(inst) ||
297+ (m_pattern->IsSourceOfSample(inst) && m_pCtx->getModule()->getNamedMetadata(NAMED_METADATA_COARSE_PHASE) != nullptr) ||
298+ (m_pattern->IsSourceOfSample(inst) && !m_pattern->NeedVMask()) ||
299+ (m_pattern->IsSourceOfSample(inst) && m_pattern->NeedVMask() && m_pattern->IsSourceOfSampleUnderCF(inst)));
300+ }
301+
293302uint EmitPass::DecideInstanceAndSlice(const llvm::BasicBlock& blk, SDAG& sdag, bool& slicing)
294303{
295304 m_encoder->SetSubSpanDestination(false);
@@ -317,11 +326,7 @@ uint EmitPass::DecideInstanceAndSlice(const llvm::BasicBlock& blk, SDAG& sdag, b
317326 m_destination = GetSymbol(sdag.m_root);
318327 numInstance = m_destination->GetNumberInstance();
319328
320- if (m_pattern->IsSubspanUse(sdag.m_root) && IsNoMaskAllowed(sdag) &&
321- (!m_pattern->IsSourceOfSample(sdag.m_root) ||
322- (m_pattern->IsSourceOfSample(sdag.m_root) && m_pCtx->getModule()->getNamedMetadata(NAMED_METADATA_COARSE_PHASE) != nullptr) ||
323- (m_pattern->IsSourceOfSample(sdag.m_root) && !m_pattern->NeedVMask()) ||
324- (m_pattern->IsSourceOfSample(sdag.m_root) && m_pattern->NeedVMask() && m_pattern->IsSourceOfSampleUnderCF(sdag.m_root))))
329+ if (IsSubspanDestination(sdag.m_root))
325330 {
326331 m_encoder->SetSubSpanDestination(true);
327332 }
@@ -9627,6 +9632,75 @@ void EmitPass::EmitInlineAsm(llvm::CallInst* inst)
96279632 str << "/// End Inlined ASM" << endl << endl;
96289633}
96299634
9635+ void EmitPass::EmitInitializePHI(llvm::PHINode* phi)
9636+ {
9637+ if (m_destination->IsUniform())
9638+ {
9639+ return;
9640+ }
9641+ if (m_deSSA && m_deSSA->getRootValue(phi) != nullptr)
9642+ {
9643+ // If this phi is not isolated, it can be safely initialized only if no
9644+ // other values it is coalesced with use NoMask on their destinations.
9645+ // NoMask could be used if the other value is:
9646+ // - uniform(handled above)
9647+ // - also a phi that is being initialized
9648+ // - emitted with m_SubSpanDestination set to true
9649+ {
9650+ SmallVector<Value*, 16> coalescedValues;
9651+ m_deSSA->getAllCoalescedValues(phi, coalescedValues);
9652+ for (auto val : coalescedValues)
9653+ {
9654+ if (val != phi &&
9655+ (isa<PHINode>(val) && m_pattern->IsSourceOfSample(val)) ||
9656+ (isa<Instruction>(val) && IsSubspanDestination(cast<Instruction>(val))))
9657+ {
9658+ return;
9659+ }
9660+ }
9661+ }
9662+ }
9663+
9664+ if (m_destination->GetType() == ISA_TYPE_BOOL)
9665+ {
9666+ CVariable* initializedTempVar = m_currShader->GetNewVariable(m_destination->GetNumberElement(), ISA_TYPE_UD, EALIGN_GRF, CName::NONE);
9667+ m_encoder->SetNoMask();
9668+ m_encoder->Copy(initializedTempVar, m_currShader->ImmToVariable(0, ISA_TYPE_UD));
9669+ m_encoder->Push();
9670+
9671+ m_encoder->Select(m_destination, initializedTempVar, m_currShader->ImmToVariable(0xFFFFFFFFULL, ISA_TYPE_UD), m_currShader->ImmToVariable(0, ISA_TYPE_UD));
9672+ m_encoder->Push();
9673+
9674+ CVariable* initializedFlag = m_currShader->GetNewVariable(m_destination);
9675+ VISA_Type type = GetTypeFromSize(m_destination->GetNumberElement() / BITS_PER_BYTE);
9676+ m_encoder->SetNoMask();
9677+ m_encoder->SetP(initializedFlag, m_currShader->ImmToVariable(0, type));
9678+ m_encoder->Push();
9679+
9680+ m_encoder->Cmp(EPREDICATE_EQ, initializedFlag, initializedTempVar, m_currShader->ImmToVariable(0xFFFFFFFFULL, ISA_TYPE_UD));
9681+ m_encoder->Push();
9682+
9683+ m_encoder->Copy(m_destination, initializedFlag);
9684+ m_encoder->Push();
9685+ }
9686+ else
9687+ {
9688+ VISA_Type unsignedType = GetUnsignedIntegerType(m_destination->GetType());
9689+ CVariable* initializedVar = m_currShader->GetNewVariable(m_destination);
9690+ CVariable* udAlias = m_currShader->GetNewAlias(initializedVar, unsignedType, 0, m_destination->GetNumberElement());
9691+ m_encoder->SetNoMask();
9692+ m_encoder->Copy(udAlias, m_currShader->ImmToVariable(0, unsignedType));
9693+ m_encoder->Push();
9694+
9695+ m_encoder->Copy(initializedVar, m_destination);
9696+ m_encoder->Push();
9697+
9698+ m_encoder->SetNoMask();
9699+ m_encoder->Copy(m_destination, initializedVar);
9700+ m_encoder->Push();
9701+ }
9702+ }
9703+
96309704CVariable* EmitPass::Mul(CVariable* Src0, CVariable* Src1, const CVariable* DstPrototype)
96319705{
96329706 bool IsSrc0Imm = Src0->IsImmediate();
0 commit comments