[LLVMdev] [RFC] Identifying access to errno

Renato Golin renato.golin at linaro.org
Sat Nov 23 08:53:09 PST 2013


On 23 November 2013 14:14, Hal Finkel <hfinkel at anl.gov> wrote:

> On some systems (Linux/glibc, for example), some libm math functions (like
> cos(double)) might set errno. It is important that we model this, in
> general, to prevent miscompilation (we would not, for example, want to
> reorder a call to cos in between a call to open and a call to perror).
> However, almost no code in the wild checks errno after calls to libm math
> functions, and this errno-setting behavior prevents vectorization and other
> useful loop optimizations, CSE, etc. Also, currently, the scalar llvm.<libm
> function> intrinsics are subtly broken on systems where the underlying libm
> functions may set errno, because the intrinsics are readonly, and may be
> implemented by calls to the libm function (which might set errno), exposing
> us to reordering problems (as in the example above).
>

Hi Hal,

I'm confused. On one hand you're proposing us to stop reordering libm calls
because they might set errno (I agree with this), but on the other hand
you're saying that nobody cares and that prevents optimizations (not sure I
agree with this).


 1. Assume that all unknown external functions might read/write errno

 2. Assume that all i32 pointers might point to errno (although we might be
> able to do better by somehow leveraging TBAA for "int"?)
>

Something like "MayBeErr", "IsErr", "IsntErr".


Does anyone see any problems with making stronger (type-based) assumptions
> re: errno (and, thus, on what things may alias with calls to
> errno-setting-libm functions)?


I don't, but I'm trying to think of a way to disable it if we know it's
"ok". Maybe -unsafe-math or something similar could disable this pass,
because it is expensive and will impact generated code.


What if, for globals, we insisted that the global be named "errno"?
>

I wouldn't be surprised if there was a system where the golbal error is not
errno. Windows maybe?

--renato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131123/36e00463/attachment.html>


More information about the llvm-dev mailing list