Commit 1f3d02f6 authored by Mochocki, Piotr's avatar Mochocki, Piotr Committed by gbsbuild

Changes in code.

Change-Id: I373dcb9f676144eb0a49a5a44866851d762c5b39
parent ea20ce0d
......@@ -1365,7 +1365,7 @@ auto sizeToSIMDMode = [](uint32_t size)
}
};
CVariable* CShader::GetConstant(llvm::Value* V, CVariable* dstVar)
CVariable* CShader::GetConstant(llvm::Value* V)
{
llvm::Constant *C = llvm::dyn_cast<llvm::Constant>(V);
assert (C && "V must be Constant");
......@@ -1383,8 +1383,8 @@ CVariable* CShader::GetConstant(llvm::Value* V, CVariable* dstVar)
return GetScalarConstant(EC);
}
CVariable* CVar = (dstVar == nullptr) ?
GetNewVariable(elts, GetType(eTy), EALIGN_GRF, true) : dstVar;
CVariable *CVar = GetNewVariable(elts, GetType(eTy), EALIGN_GRF, true);
unsigned i = 0;
// Emit a scalar move to load the element of index k.
auto copyScalar = [=](int k)
......@@ -1413,6 +1413,52 @@ CVariable* CShader::GetConstant(llvm::Value* V, CVariable* dstVar)
uint remainElts = elts;
uint currentEltsOffset = 0;
uint size = 8;
unsigned NBits = VTy->getScalarSizeInBits();
// case 1: Pack multiple elements into a single 64 bit immediate.
if (VTy->isIntOrIntVectorTy() && NBits < 64 && !m_Platform->hasNo64BitInst())
{
assert(64 % NBits == 0 && "unsupported scalar type");
unsigned Step = 64 / NBits;
unsigned End = (int_cast<unsigned>(VTy->getNumElements()) / Step) * Step;
for (; i < End; i += Step)
{
// Pack bits: <i16 1, i16 2, i16 3, i16 4> ==> 0x 0004 0003 0002 0001
uint64_t PVal = 0;
bool AllUndef = true;
for (unsigned j = 0; j < Step; ++j)
{
Constant *Elt = C->getAggregateElement(i + j);
if (auto CI = dyn_cast<ConstantInt>(Elt))
{
uint64_t Bits = CI->getZExtValue();
PVal |= Bits << (j * VTy->getScalarSizeInBits());
AllUndef = false;
}
else
{
assert(isa<UndefValue>(Elt));
}
}
if (AllUndef)
continue;
CVariable *PVar = ImmToVariable(PVal, ISA_TYPE_UQ);
unsigned OffsetInBytes = i * VTy->getScalarSizeInBits() / 8;
CVariable *AliasVar =
GetNewAlias(CVar, ISA_TYPE_UQ, (uint16_t)OffsetInBytes, 1);
GetEncoder().Copy(AliasVar, PVar);
GetEncoder().Push();
}
// Element-wise copy or trailing elements copy if partially packed.
for (; i < VTy->getNumElements(); ++i)
{
copyScalar(i);
}
return CVar;
}
while (remainElts != 0)
{
......
......@@ -9050,18 +9050,10 @@ void EmitPass::emitInsert(llvm::Instruction* inst)
llvm::Type* pVecType = inst->getType();
if (!isa<UndefValue>(pVec))
{
if (isa<ConstantVector>(pVec))
pVecVar = GetSymbol(pVec);
if (pVecVar != pInstVar)
{
auto CV = cast<ConstantVector>(pVec);
pInstVar = m_currShader->GetConstant(CV, pInstVar);
}
else
{
pVecVar = GetSymbol(pVec);
if (pVecVar != pInstVar)
{
emitVectorCopy(pInstVar, pVecVar, int_cast<unsigned>(dyn_cast<VectorType>(pVecType)->getNumElements()));
}
emitVectorCopy(pInstVar, pVecVar, int_cast<unsigned>(dyn_cast<VectorType>(pVecType)->getNumElements()));
}
}
......
......@@ -157,7 +157,7 @@ public:
void AllocateInput(CVariable* var, uint offset, uint instance = 0);
void AllocateOutput(CVariable* var, uint offset, uint instance = 0);
CVariable* ImmToVariable(uint64_t immediate, VISA_Type type);
CVariable* GetConstant(llvm::Value* c, CVariable* dstVar = nullptr);
CVariable* GetConstant(llvm::Value* c);
CVariable* GetScalarConstant(llvm::Value* c);
CVariable* GetUndef(VISA_Type type);
llvm::Constant* findCommonConstant(llvm::Constant *C, uint elts, uint currentEmitElts, bool &allSame);
......
......@@ -953,26 +953,6 @@ void GenSpecificPattern::visitBinaryOperator(BinaryOperator &I)
}
}
}
else if (I.getOpcode() == Instruction::Shl)
{
auto op0 = dyn_cast<ZExtInst>(I.getOperand(0));
auto offset = llvm::dyn_cast<llvm::ConstantInt>(I.getOperand(1));
if (op0 &&
op0->getType()->isIntegerTy(64) &&
op0->getOperand(0)->getType()->isIntegerTy(32) &&
offset &&
offset->getZExtValue() == 32)
{
llvm::IRBuilder<> builder(&I);
auto vec2 = VectorType::get(builder.getInt32Ty(), 2);
Value* vec = UndefValue::get(vec2);
vec = builder.CreateInsertElement(vec, builder.getInt32(0), builder.getInt32(0));
vec = builder.CreateInsertElement(vec, op0->getOperand(0), builder.getInt32(1));
vec = builder.CreateBitCast(vec, builder.getInt64Ty());
I.replaceAllUsesWith(vec);
I.eraseFromParent();
}
}
}
void GenSpecificPattern::visitCmpInst(CmpInst &I)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment