compiler-optimization

LLVM opt mem2reg has no effect

走远了吗. 提交于 2019-12-05 00:51:51
问题 I am currently playing around with LLVM and am trying to write a few optimizers to familiarize myself with opt and clang. I wrote a test.c file that is as follow: int foo(int aa, int bb, int cc){ int sum = aa + bb; return sum/cc; } I compiled the source code and generated 2 .ll files, one unoptimized and one with mem2reg optimizer pass: clang -emit-llvm -O0 -c test.c -o test.bc llvm-dis test.bc opt -mem2reg -S test.ll -o test-mem2reg.ll Both .ll files gave me the following output: ModuleID =

Why does the compiler assume that these seemingly equal pointers differ?

旧街凉风 提交于 2019-12-05 00:29:09
Looks like GCC with some optimization thinks two pointers from different translation units can never be same even if they are actually the same. Code: main.c #include <stdint.h> #include <stdio.h> int a __attribute__((section("test"))); extern int b; void check(int cond) { puts(cond ? "TRUE" : "FALSE"); } int main() { int * p = &a + 1; check( (p == &b) == ((uintptr_t)p == (uintptr_t)&b) ); check(p == &b); check((uintptr_t)p == (uintptr_t)&b); return 0; } b.c int b __attribute__((section("test"))); If I compile it with -O0, it prints TRUE TRUE TRUE But with -O1 FALSE FALSE TRUE So p and &b are

“Function has no address” despite disabled optimization (/Od)

限于喜欢 提交于 2019-12-04 23:49:56
During debug in MSVC 2012, I am attempting to call some functions from the Watch window in order to dump data to files. However, I keep getting this error: Function Matrix::Save has no address, possibly due to compiler optimizations. The class Matrix is located in my own external library. A quick check showed that none of the methods in external libraries have addresses and all attempts to call them from Watch return this error, except for those which are defined in the header files. The methods in the main project all have addresses regardless of where they are defined. Optimization is

Forcing GCC to perform loop unswitching of memcpy runtime size checks?

只愿长相守 提交于 2019-12-04 23:44:06
Is there any reliable way to force GCC (or any compiler) to factor out runtime size checks in memcpy() outside of a loop (where that size is not compile-time constant, but constant within that loop), specializing the loop for each relevant size range rather than repeatedly checking the size within it? This is an test case reduced down from a performance regression reported here for an open source library designed for efficient in-memory analysis of large data sets. (The regression happens to be because of one of my commits...) The original code is in Cython, but I've reduced it down to a pure

Why would a compiler generate this assembly?

送分小仙女□ 提交于 2019-12-04 22:51:46
While stepping through some Qt code I came across the following. The function QMainWindowLayout::invalidate() has the following implementation: void QMainWindowLayout::invalidate() { QLayout::invalidate() minSize = szHint = QSize(); } It is compiled to this: <invalidate()> push %rbx <invalidate()+1> mov %rdi,%rbx <invalidate()+4> callq 0x7ffff4fd9090 <QLayout::invalidate()> <invalidate()+9> movl $0xffffffff,0x564(%rbx) <invalidate()+19> movl $0xffffffff,0x568(%rbx) <invalidate()+29> mov 0x564(%rbx),%rax <invalidate()+36> mov %rax,0x56c(%rbx) <invalidate()+43> pop %rbx <invalidate()+44> retq

How should I detect bottleneck of compile time in a large C++ project?

岁酱吖の 提交于 2019-12-04 22:27:54
I want to reduce compile time of a large C++ project. I tried to use precompiled headers, interface and etc. But before I move on, I want to know whether any tool which helps detect why compile time is so long. Somebody suggests pc-lint and I will give a shot. How should I detect unnecessary #include files in a large C++ project? But if there are other tools which analysis compile time and talk about any hints to increase compile speed, let me know. Thanks in advance. Environment : Microsoft Visual Studio C++ 2008 or 2010. one approach i like is to review the preprocessor output of a few of

simple compiler for optimization purposes

江枫思渺然 提交于 2019-12-04 18:10:58
I want a source code of a simple compiler to optimize by interchanging the code for delayed branches for my assignment. I read the is there a simple compiler for a small language question and found several good compilers. But optimization has done for almost all of them and some links are dead. Can someone recommend me a simple compiler for a small language that is not implemented optimization for delayed branches. You might try: cucu: a compiler you can understand It is a simple C compiler, less than 700 lines of code. I found it well written and easy to follow. 来源: https://stackoverflow.com

slow JDK8 compilation

僤鯓⒐⒋嵵緔 提交于 2019-12-04 17:13:48
Trying to upgrade to JDK8 on a big project, compilation goes really slow on JDK8 compared to JDK7. Running the compiler in verbose mode, JDK8 compiler stops at a big generated converter class(Mapping) for entities from server to client. The converter methods in several cases call other converter methods from the same Mapping class. As a workaround tried to split the Mapping file into multiple files. This visibly improved performance when only compiling the Mapping class or it's containing project(projectA). But compile time was very slow for other projects which invoke converter methods from

Does undefined behavior really help modern compilers to optimize generated code?

大憨熊 提交于 2019-12-04 16:49:45
Aren't modern compilers smart enough to be able to generate a code that is fast and safe at the same time? Look at the code below: std::vector<int> a(100); for (int i = 0; i < 50; i++) { a.at(i) = i; } ... It's obvious that the out of range error will never happen here, and a smart compiler can generate the next code: std::vector<int> a(100); for (int i = 0; i < 50; i++) { a[i] = i; } // operator[] doesn't check for out of range ... Now let's check this code: std::vector<int> a(unknown_function()); for (int i = 0; i < 50; i++) { a.at(i) = i; } ... It can be changed to such equivalent: std:

How not specify an exact order of evaluation of function argument helps C & C++ compiler to generate optimized code?

坚强是说给别人听的谎言 提交于 2019-12-04 15:43:11
#include <iostream> int foo() { std::cout<<"foo() is called\n"; return 9; } int bar() { std::cout<<"bar() is called\n"; return 18; } int main() { std::cout<<foo()<<' '<<bar()<<' '<<'\n'; } // Above program's behaviour is unspecified // clang++ evaluates function arguments from left to right: http://melpon.org/wandbox/permlink/STnvMm1YVrrSRSsB // g++ & MSVC++ evaluates function arguments from right to left // so either foo() or bar() can be called first depending upon compiler. Output of above program is compiler dependent. Order in which function arguments are evaluated is unspecified . The