[llvm-bugs] [Bug 28937] New: clang is not knowing using const-attribute for the standard math functions

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 11 06:07:46 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28937

            Bug ID: 28937
           Summary: clang is not knowing using const-attribute for the
                    standard math functions
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: npl at chello.at
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

unlike gcc, clang doesn`t seem to have the knowledge about std math functions
builtin.

Similar to knowing memcpy and generating optimized code, clang should know that
all math functions only depend on their arguments.

For the code snippet below, I would expect that
* Clang should only call the function once

What happens is that
* Clang cant deduce that the function is "const" and doesnt remove any call

(apparently this could also be solved in the std library, but I doubt its wise
to depend on this, rather than simply expect that the standard functions are
deterministic)

------------ (code snippet)
#include <math.h>

float failttooptimize(float a)
{
  return sin(a) + sin(a) + sin(a);
}

__attribute__((const)) double cos(double a);
float canoptimize(float a)
{
  return cos(a) + cos(a) + cos(a);
}
------------

clang version 3.8.1-5 (tags/RELEASE_381/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.9.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
 "/usr/lib/llvm-3.8/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -S
-disable-free -disable-llvm-verifier -main-file-name test.c -mrelocation-model
static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer
-v -dwarf-column-info -debugger-tuning=gdb -coverage-file /tmp/test.c
-resource-dir /usr/lib/llvm-3.8/bin/../lib/clang/3.8.1 -internal-isystem
/usr/local/include -internal-isystem
/usr/lib/llvm-3.8/bin/../lib/clang/3.8.1/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -O3 -fdebug-compilation-dir /tmp
-ferror-limit 19 -fmessage-length 211 -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp
-o test.s -x c test.c
clang -cc1 version 3.8.1 based upon LLVM 3.8.1 default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/llvm-3.8/bin/../lib/clang/3.8.1/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160811/11e83d04/attachment.html>


More information about the llvm-bugs mailing list