Commit 2bb38537 authored by Thomas's avatar Thomas Committed by gbsbuild

Combine itof + ftoi to round to zero instruction

Change-Id: I1688bcb0c7ec4f7fe53dc494a3ede99770c3c685
parent d61a476e
......@@ -1116,6 +1116,37 @@ void GenSpecificPattern::visitSelectInst(SelectInst &I)
}
void GenSpecificPattern::visitCastInst(CastInst &I)
{
Instruction* srcVal = nullptr;
if(isa<SIToFPInst>(&I))
{
srcVal = dyn_cast<FPToSIInst>(I.getOperand(0));
}
else if(isa<UIToFPInst>(&I))
{
srcVal = dyn_cast<FPToUIInst>(I.getOperand(0));
}
if(srcVal && srcVal->getOperand(0)->getType() == I.getType())
{
if(srcVal = dyn_cast<Instruction>(srcVal->getOperand(0)))
{
// need fast math to know that we can ignore Nan
if(srcVal->isFast())
{
IRBuilder<> builder(&I);
Function* func = Intrinsic::getDeclaration(
I.getParent()->getParent()->getParent(),
Intrinsic::trunc,
I.getType());
Value* newVal = builder.CreateCall(func, srcVal);
I.replaceAllUsesWith(newVal);
I.eraseFromParent();
}
}
}
}
void GenSpecificPattern::visitZExtInst(ZExtInst &ZEI)
{
CmpInst *Cmp = dyn_cast<CmpInst>(ZEI.getOperand(0));
......
......@@ -122,6 +122,7 @@ namespace IGC
void visitSelectInst(llvm::SelectInst &I);
void visitCmpInst(llvm::CmpInst &I);
void visitZExtInst(llvm::ZExtInst &I);
void visitCastInst(llvm::CastInst &I);
void visitIntToPtr(llvm::IntToPtrInst& I);
void visitSDiv(llvm::BinaryOperator& 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