Skip to content

Commit a2202c4

Browse files
jgu222sys_zuul
authored andcommitted
When doing bitcast of immediate, if the dst type has the same size as the
original one, it is okay to regenerate imm with dst's type (exisiting code). If the dst type is a vector type, we need to create a temp var, initialized with the imm, and return the alias to the new temp var. Change-Id: I2ca811e385e91f682976b5ba209df1e598513e84
1 parent bda005b commit a2202c4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,32 @@ CVariable* CShader::GetGlobalCVar(llvm::Value* value)
857857
CVariable* CShader::BitCast(CVariable* var, VISA_Type newType)
858858
{
859859
CVariable* bitCast = nullptr;
860+
uint32_t newEltSz = CEncoder::GetCISADataTypeSize(newType);
861+
uint32_t eltSz = var->GetElemSize();
862+
// Bitcase requires both src and dst have the same size, which means
863+
// one element size is the same as or multiple of the other (if they
864+
// are vectors with different number of elements).
865+
IGC_ASSERT( (newEltSz >= eltSz && (newEltSz % eltSz) == 0)
866+
|| (newEltSz < eltSz && (eltSz% newEltSz) == 0));
860867
if (var->IsImmediate())
861868
{
862-
bitCast = ImmToVariable(var->GetImmediateValue(), newType);
869+
if (newEltSz == eltSz)
870+
bitCast = ImmToVariable(var->GetImmediateValue(), newType);
871+
else
872+
{
873+
// Need a temp. For example, bitcast i64 0 -> 2xi32
874+
CVariable* tmp = GetNewVariable(
875+
1,
876+
var->GetType(),
877+
CEncoder::GetCISADataTypeAlignment(var->GetType()),
878+
true,
879+
1,
880+
"vecImmBitCast");
881+
encoder.Copy(tmp, var);
882+
encoder.Push();
883+
884+
bitCast = GetNewAlias(tmp, newType, 0, 0);
885+
}
863886
}
864887
else
865888
{

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ void EmitPass::Mul64(CVariable* dst, CVariable* src[2], SIMDMode simdMode, bool
30203020
CVariable* srcLo[2], * srcHi[2];
30213021
for (int i = 0; i < 2; ++i)
30223022
{
3023-
CVariable* srcAsUD = m_currShader->BitCast(src[i], ISA_TYPE_UD);
3023+
CVariable* srcAsUD;
30243024
if (src[i]->IsUniform())
30253025
{
30263026
if (src[i]->IsImmediate())
@@ -3030,12 +3030,14 @@ void EmitPass::Mul64(CVariable* dst, CVariable* src[2], SIMDMode simdMode, bool
30303030
}
30313031
else
30323032
{
3033+
srcAsUD = m_currShader->BitCast(src[i], ISA_TYPE_UD);
30333034
srcLo[i] = m_currShader->GetNewAlias(srcAsUD, ISA_TYPE_UD, 0, 1);
30343035
srcHi[i] = m_currShader->GetNewAlias(srcAsUD, hiType, SIZE_DWORD, 1);
30353036
}
30363037
}
30373038
else
30383039
{
3040+
srcAsUD = m_currShader->BitCast(src[i], ISA_TYPE_UD);
30393041
//TODO: Would it be better for these two to be consecutive?
30403042
srcLo[i] = m_currShader->GetNewVariable(
30413043
src[i]->GetNumberElement(),

0 commit comments

Comments
 (0)