Motivation: https://bugs.llvm.org/show_bug.cgi?id=34870
I'm totally not sure this is correct
Details
Diff Detail
Event Timeline
I don't know the history of the frem instruction in IR, and the description in http://llvm.org/docs/LangRef.html#frem-instruction is vague.
But based on the existing code, I think this is working as intended. If the instruction has the same semantics as the math library function 'fmod', then we do want to convert this to an IR instruction in clang.
Note that when I filed PR34870, I assumed the bug was in the IR optimizer in the instcombine pass, but if the IR instruction does not match the semantics of the math library function, then I'd be wrong. :)
Side note: I think there is a different bug here in clang because from what I can tell, we convert the builtin or libcall to 'frem' even when errno could be set by the call. D40044 doesn't address this case because frem is an LLVM instruction rather than an LLVM intrinsic.
By many years of precedent, the "frem" instruction is supposed to match the C fmod(), as opposed to something else like the C99 remainder(); probably worth clarifying in LangRef.