Details
- Reviewers
davide
Diff Detail
Event Timeline
SimplifyLibCalls.cpp does a similar transformation (cos(-x) -> cos(x)).
I think we should have the logic for this simplifications in a single place, if possible, so maybe there we should unconditionally lower libc cos() -> llvm.cos and simplify here?
I think that needs to be part of a larger change to fix the mess of math intrinsic and libcall handling. In the case of cos, I view the cos function as somewhat different from llvm.cos. I expect the intrinsic to be a possibly less precise machine instruction version of cos rather than a fully correct library call so I'm not sure it should always be replaced with the intrinsic.
This is not the case, it is supposed to behave exactly as the libcall: http://llvm.org/docs/LangRef.html#id439
Not quite, as that would violate LangRef cos semantic. http://llvm.org/docs/LangRef.html#llvm-cos-intrinsic
The C standard is uselessly underspecified. It doesn't have any constraints on the precision of math functions. IMO having the intrinsic be the same as the libcall is not useful. e.g. errno is not a meaningful concept on all platforms, and the intent of intrinsics is usually to map to a machine instruction.
I don't necessarily disagree, but I think that changing the semantic of cos would require a much wider discussion on llvm-dev.
Getting back on topic, is there any objection to doing this optimization for the intrinsic (and for llvm.amdgcn.cos) separately here?
I think this is fine but if we go this route the code in SimplifyLibCalls should be removed and we should always lower there to @llvm.cos (as we do already for other intrinsics, FWIW, e.g. @llvm.fls)
lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1641 | While here, I also noticed the amdgcn_cos is not documented in LangRef, maybe it could be (or somewhere else) |
lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1641 | Do we have formal documentation for target specific intrinsics? I thought only generic intrinsics belonged in the LangRef |
lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1643–1649 | Please match against fabs as well here and update the tests. |
While here, I also noticed the amdgcn_cos is not documented in LangRef, maybe it could be (or somewhere else)