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:
@@ -2153,11 +2153,17 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
|
||||
Code = bitc::FUNC_CODE_INST_CALL;
|
||||
|
||||
Vals.push_back(VE.getAttributeID(CI.getAttributes()));
|
||||
|
||||
unsigned Flags = GetOptimizationFlags(&I);
|
||||
Vals.push_back(CI.getCallingConv() << bitc::CALL_CCONV |
|
||||
unsigned(CI.isTailCall()) << bitc::CALL_TAIL |
|
||||
unsigned(CI.isMustTailCall()) << bitc::CALL_MUSTTAIL |
|
||||
1 << bitc::CALL_EXPLICIT_TYPE |
|
||||
unsigned(CI.isNoTailCall()) << bitc::CALL_NOTAIL);
|
||||
unsigned(CI.isNoTailCall()) << bitc::CALL_NOTAIL |
|
||||
unsigned(Flags != 0) << bitc::CALL_FMF);
|
||||
if (Flags != 0)
|
||||
Vals.push_back(Flags);
|
||||
|
||||
Vals.push_back(VE.getTypeID(FTy));
|
||||
PushValueAndType(CI.getCalledValue(), InstID, Vals, VE); // Callee
|
||||
|
||||
|
||||
Reference in New Issue
Block a user