Skip to content

Commit 0a58ba2

Browse files
lfilipkoigcbot
authored andcommitted
The LopPrecisionOpt does not support scalars
and vectors of less than 4 elements. This change adds support of these data types.
1 parent 47678c3 commit 0a58ba2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

IGC/Compiler/LowPrecisionOptPass.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,25 @@ bool LowPrecisionOpt::propagateSamplerType(llvm::GenIntrinsicInst& I)
168168
return false;
169169
}
170170

171-
Type* eltTy = cast<VectorType>(I.getType())->getElementType();
171+
Type* eltTy = NULL;
172+
bool isFloatType = false;
173+
174+
if (I.getType()->isVectorTy())
175+
{
176+
eltTy = cast<VectorType>(I.getType())->getElementType();
177+
isFloatType = cast<VectorType>(I.getType())->getElementType()->isFloatTy();
178+
}
179+
else
180+
{
181+
eltTy = I.getType();
182+
isFloatType = I.getType()->isFloatTy();
183+
}
184+
172185
Type* newDstType = nullptr;
173186
if (eltTy->isFloatingPointTy())
174187
{
175188
// check that all uses are extractelement followed by fpext
176-
newDstType = cast<VectorType>(I.getType())->getElementType()->isFloatTy() ?
189+
newDstType = isFloatType ?
177190
m_builder->getHalfTy() : m_builder->getFloatTy();
178191
for (auto use = I.user_begin(); use != I.user_end(); ++use)
179192
{
@@ -236,9 +249,15 @@ bool LowPrecisionOpt::propagateSamplerType(llvm::GenIntrinsicInst& I)
236249
return false;
237250
}
238251

239-
VectorType* oldTy = cast<VectorType>(I.getType());
252+
unsigned int numberOfElements = 1;
253+
254+
if (I.getType()->isVectorTy())
255+
{
256+
numberOfElements = int_cast<unsigned int>(cast<VectorType>(I.getType())->getNumElements());
257+
}
258+
240259
llvm::SmallVector<llvm::Type*, 4> overloadTys;
241-
auto retTy = IGCLLVM::FixedVectorType::get(newDstType, int_cast<unsigned int>(oldTy->getNumElements()));
260+
auto retTy = IGCLLVM::FixedVectorType::get(newDstType, numberOfElements);
242261
overloadTys.push_back(retTy);
243262
auto ID = I.getIntrinsicID();
244263
switch (ID)

0 commit comments

Comments
 (0)