add fast-math-flags to 'call' instructions (PR21290)
This patch adds optional fast-math-flags (the same that apply to fmul/fadd/fsub/fdiv/frem/fcmp) to call instructions in IR. Follow-up patches would use these flags in LibCallSimplifier, add support to clang, and extend FMF to the DAG for calls. Motivating example: %y = fmul fast float %x, %x %z = tail call float @sqrtf(float %y) We'd like to be able to optimize sqrt(x*x) into fabs(x). We do this today using a function-wide attribute for unsafe-math, but we really want to trigger on the instructions themselves: %z = tail call fast float @sqrtf(float %y) because in an LTO build it's possible that calls with fast semantics have been inlined into a function with non-fast semantics. The code changes and tests are based on the recent commits that added "notail": http://reviews.llvm.org/rL252368 and added FMF to fcmp: http://reviews.llvm.org/rL241901 Differential Revision: http://reviews.llvm.org/D14707 llvm-svn: 255555
This commit is contained in:
@@ -5006,7 +5006,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
|
||||
break;
|
||||
}
|
||||
case bitc::FUNC_CODE_INST_CALL: {
|
||||
// CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
|
||||
// CALL: [paramattrs, cc, fmf, fnty, fnid, arg0, arg1...]
|
||||
if (Record.size() < 3)
|
||||
return error("Invalid record");
|
||||
|
||||
@@ -5014,6 +5014,13 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
|
||||
AttributeSet PAL = getAttributes(Record[OpNum++]);
|
||||
unsigned CCInfo = Record[OpNum++];
|
||||
|
||||
FastMathFlags FMF;
|
||||
if ((CCInfo >> bitc::CALL_FMF) & 1) {
|
||||
FMF = getDecodedFastMathFlags(Record[OpNum++]);
|
||||
if (!FMF.any())
|
||||
return error("Fast math flags indicator set for call with no FMF");
|
||||
}
|
||||
|
||||
FunctionType *FTy = nullptr;
|
||||
if (CCInfo >> bitc::CALL_EXPLICIT_TYPE & 1 &&
|
||||
!(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
|
||||
@@ -5075,6 +5082,12 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
|
||||
TCK = CallInst::TCK_NoTail;
|
||||
cast<CallInst>(I)->setTailCallKind(TCK);
|
||||
cast<CallInst>(I)->setAttributes(PAL);
|
||||
if (FMF.any()) {
|
||||
if (!isa<FPMathOperator>(I))
|
||||
return error("Fast-math-flags specified for call without "
|
||||
"floating-point scalar or vector return type");
|
||||
I->setFastMathFlags(FMF);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case bitc::FUNC_CODE_INST_VAARG: { // VAARG: [valistty, valist, instty]
|
||||
|
||||
Reference in New Issue
Block a user