mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Teach InstCombine to hoist FABS and FNEG through FPTRUNC instructions. The application of these operations commutes with the truncation, so we should prefer to do them in the smallest size we can, to save register space, use smaller constant pool entries, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1204,8 +1204,34 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// (fptrunc (fneg x)) -> (fneg (fptrunc x))
|
||||
if (BinaryOperator::isFNeg(OpI)) {
|
||||
Value *InnerTrunc = Builder->CreateFPTrunc(OpI->getOperand(1),
|
||||
CI.getType());
|
||||
return BinaryOperator::CreateFNeg(InnerTrunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI.getOperand(0));
|
||||
if (II) {
|
||||
switch (II->getIntrinsicID()) {
|
||||
default: break;
|
||||
case Intrinsic::fabs: {
|
||||
// (fptrunc (fabs x)) -> (fabs (fptrunc x))
|
||||
Value *InnerTrunc = Builder->CreateFPTrunc(II->getArgOperand(0),
|
||||
CI.getType());
|
||||
Type *IntrinsicType[] = { CI.getType() };
|
||||
Function *Overload =
|
||||
Intrinsic::getDeclaration(CI.getParent()->getParent()->getParent(),
|
||||
II->getIntrinsicID(), IntrinsicType);
|
||||
|
||||
Value *Args[] = { InnerTrunc };
|
||||
return CallInst::Create(Overload, Args, II->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
|
||||
CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
|
||||
if (Call && Call->getCalledFunction() && TLI->has(LibFunc::sqrtf) &&
|
||||
|
Reference in New Issue
Block a user