mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Reimplement r108639 in InstCombine rather than DAGCombine.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108687 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
926f2bb3d8
commit
d90290127b
@ -1097,6 +1097,32 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
|
||||
// NOTE: This should be disabled by -fno-builtin-sqrt if we ever support it.
|
||||
CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
|
||||
if (Call && Call->getCalledFunction() &&
|
||||
Call->getCalledFunction()->getName() == "sqrt" &&
|
||||
Call->getNumArgOperands() == 1) {
|
||||
CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
|
||||
if (Arg && Arg->getOpcode() == Instruction::FPExt &&
|
||||
CI.getType() == Builder->getFloatTy() &&
|
||||
Call->getType() == Builder->getDoubleTy() &&
|
||||
Arg->getType() == Builder->getDoubleTy() &&
|
||||
Arg->getOperand(0)->getType() == Builder->getFloatTy()) {
|
||||
Module* M = CI.getParent()->getParent()->getParent();
|
||||
Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf",
|
||||
Call->getAttributes(),
|
||||
Builder->getFloatTy(),
|
||||
Builder->getFloatTy(),
|
||||
NULL);
|
||||
CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
|
||||
"sqrtfcall");
|
||||
ret->setAttributes(Call->getAttributes());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user