This is an archive of the discontinued LLVM Phabricator instance.

Add strictfp attribute to prevent unwanted optimizations of libm calls
ClosedPublic

Authored by andrew.w.kaylor on Jun 13 2017, 1:07 PM.

Details

Summary

In preparation for supporting the STDC FENV_ACCESS pragma (and related other pragmas), we need a way to prevent optimizations to libm function calls. To accomplish this, I am adding a new function attribute, strictfp, which tells the optimizer to handle these calls specially. This attribute should behave similarly to the nobuiltin attribute, but it isn't quite as restrictive. In particular, it allows optimizations that would be blocked by nobuiltin as long as the optimization is not related to FP semantics.

Since we don't expect (or want) the front end to maintain knowledge about which functions the optimizer recognizes as LibFuncs, the expectation is that the front end will attach the strictfp attribute to all function calls within any scope where FENV_ACCESS is enabled. This should have no effect for functions that are not FP-related.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper added inline comments.Jun 23 2017, 1:42 PM
include/llvm/Bitcode/LLVMBitCodes.h
552

Maybe just leave a trailnig comma on the end here so the next guy doesn't have to add one. Looks like the 2 enums below have a trailing comma.

lib/AsmParser/LLParser.cpp
1124

Should this be after sspstrong to match the order in LLLexer.cpp which seems to be mostly alphabetical except for the sanitize and safestack?

lib/AsmParser/LLToken.h
212

Wow how many different not alphabetical orders do we have on these keywords?

lib/Transforms/Utils/SimplifyLibCalls.cpp
2055

Doesnt' the caller already check getLibFunc and TLI->has?

andrew.w.kaylor added inline comments.Jul 6 2017, 3:22 PM
lib/AsmParser/LLToken.h
212

Yeah, if you don't object I'm going to leave this patch in the "approximately alphabetical" state it's in and maybe clean them all up afterward in a separate patch.

lib/Transforms/Utils/SimplifyLibCalls.cpp
2055

Yes, but I need to call getLibFunc() here to get the Func (or I could pass it as an argument). I chose to do it this way to mimic the behavior of optimizeStringMemoryLibCall(), but I suppose there is some benefit to avoiding the churn that getLibFunc goes through with the StringRef.

-Addressed review feedback
-Rebased

craig.topper accepted this revision.Jul 10 2017, 10:07 AM

LGTM.

Can you also add strictfp to utils/vim/syntax/llvm.vim where the other keywords are listed?

This revision is now accepted and ready to land.Jul 10 2017, 10:07 AM
This revision was automatically updated to reflect the committed changes.