Skip to content

Commit e3c43ae

Browse files
aratajewsys_zuul
authored andcommitted
Preprocess FNeg instruction before dp-emulation
Change-Id: Ia0e53bdd4680f12aec519696dcdf3c1b37fa646e
1 parent 0bc2ffe commit e3c43ae

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

IGC/Compiler/Optimizer/PreCompiledFuncImport.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,36 @@ bool PreCompiledFuncImport::preProcessDouble()
326326
toBeDeleted.push_back(CallI);
327327
}
328328
}
329+
#if LLVM_VERSION_MAJOR >= 10
330+
else if (Inst->getOpcode() == Instruction::FNeg)
331+
{
332+
if (Inst->getType()->isDoubleTy())
333+
{
334+
IRBuilder<> builder(Inst);
335+
Value* fsub = nullptr;
336+
337+
if (!Inst->getType()->isVectorTy())
338+
{
339+
fsub = builder.CreateFSub(ConstantFP::get(Inst->getType(), 0.0f), Inst->getOperand(0));
340+
}
341+
else
342+
{
343+
uint32_t vectorSize = cast<VectorType>(Inst->getType())->getNumElements();
344+
fsub = llvm::UndefValue::get(Inst->getType());
345+
346+
for (uint32_t i = 0; i < vectorSize; ++i)
347+
{
348+
Value* extract = builder.CreateExtractElement(Inst->getOperand(0), i);
349+
Value* extract_fsub = builder.CreateFSub(ConstantFP::get(extract->getType(), 0.0f), extract);
350+
fsub = builder.CreateInsertElement(fsub, extract_fsub, i);
351+
}
352+
}
353+
354+
Inst->replaceAllUsesWith(fsub);
355+
toBeDeleted.push_back(Inst);
356+
}
357+
}
358+
#endif
329359
}
330360
}
331361

0 commit comments

Comments
 (0)