[SimplifyLibCalls] Fix infinite loop with fast-math optimization.
authorAndrew Ng <anng.sw@gmail.com>
Tue, 25 Apr 2017 12:36:14 +0000 (12:36 +0000)
committerAndrew Ng <anng.sw@gmail.com>
Tue, 25 Apr 2017 12:36:14 +0000 (12:36 +0000)
commit1606fc0bf90fa984f335c7d9d7b56761afa0e67a
tree8afed9a011b2868979f7a280f8dd96087b00c178
parentab0446332e7b50328499e138b9856625a6577109
[SimplifyLibCalls] Fix infinite loop with fast-math optimization.

One of the fast-math optimizations is to replace calls to standard double
functions with their float equivalents, e.g. exp -> expf. However, this can
cause infinite loops for the following:

  float expf(float val) { return (float) exp((double) val); }

A similar inline declaration exists in the MinGW-w64 math.h header file which
when compiled with -O2/3 and fast-math generates infinite loops.

So this fix checks that the calling function to the standard double function
that is being replaced does not match the float equivalent.

Differential Revision: https://reviews.llvm.org/D31806

llvm-svn: 301304
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/Util/libcalls-fast-math-inf-loop.ll [new file with mode: 0644]