compiler-optimization

LLVM opt mem2reg has no effect

余生长醉 提交于 2019-12-03 19:32:49
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 = 'test.bc' source_filename = "test.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target

Is this a JVM bug or “expected behavior”?

﹥>﹥吖頭↗ 提交于 2019-12-03 18:22:41
问题 I noticed some unexpected behavior (unexpected relative to my personal expectations), and I'm wondering if something if there is a bug in the JVM or if perhaps this is a fringe case where I don't understand some of the details of what exactly is supposed to happen. Suppose we had the following code in a main method by itself: int i; int count = 0; for(i=0; i < Integer.MAX_VALUE; i+=2){ count++; } System.out.println(i++); A naive expectation would be that this would print Integer.MAX_VALUE-1 ,

Can't turn off gcc optimizer, Makefile from automake

旧城冷巷雨未停 提交于 2019-12-03 17:36:48
问题 I am trying to get ZBar in a debug session. I am able to do so, but I can't get the optimizer to turn off, so my debug session jumps around unexpectedly and many variables are labeled as optimized-out in Eclipse Indigo. I am running in Ubuntu. I have tried adding -O0 as far right in any gcc call in the Makefiles as possible, since the last -O is the acting one. I used -Q --help=optimizers to find what to be looking for, but its output is a bit odd: libtool: compile: gcc -DHAVE_CONFIG_H -I. -I

Does const allow for (theoretical) optimization here?

↘锁芯ラ 提交于 2019-12-03 17:28:51
问题 Consider this snippet: void foo(const int&); int bar(); int test1() { int x = bar(); int y = x; foo(x); return x - y; } int test2() { const int x = bar(); const int y = x; foo(x); return x - y; } In my understanding of the standard, neither x nor y are allowed to be changed by foo in test2 , whereas they could be changed by foo in test1 (with e.g. a const_cast to remove const from the const int& because the referenced objects aren't actually const in test1 ). Now, neither gcc nor clang nor

Will C++ linker automatically inline functions (without “inline” keyword, without implementation in header)?

ⅰ亾dé卋堺 提交于 2019-12-03 16:05:01
问题 Will the C++ linker automatically inline "pass-through" functions, which are NOT defined in the header, and NOT explicitly requested to be "inlined" through the inline keyword? For example, the following happens so often , and should always benefit from "inlining", that it seems every compiler vendor should have "automatically" handled it through "inlining" through the linker (in those cases where it is possible): //FILE: MyA.hpp class MyA { public: int foo(void) const; }; //FILE: MyB.hpp

Compiler optimization makes program crash

时光怂恿深爱的人放手 提交于 2019-12-03 15:57:29
I'm writing a program in C++/Qt which contains a graph file parser. I use g++ to compile the project. While developing, I am constantly comparing the performance of my low level parser layer between different compiler flags regarding optimization and debug information, plus Qt's debug flag (turning on/off qDebug() and Q_ASSERT()). Now I'm facing a problem where the only correctly functioning build is the one without any optimization . All other versions, even with -O1 , seem to work in another way. They crash due to unsatisfied assertions, which are satisfied when compiled without a -O... flag

gcc removes inline assembler code

北慕城南 提交于 2019-12-03 15:26:26
问题 It seems like gcc 4.6.2 removes code it considers unused from functions. test.c int main(void) { goto exit; handler: __asm__ __volatile__("jmp 0x0"); exit: return 0; } Disassembly of main() 0x08048404 <+0>: push ebp 0x08048405 <+1>: mov ebp,esp 0x08048407 <+3>: nop # <-- This is all whats left of my jmp. 0x08048408 <+4>: mov eax,0x0 0x0804840d <+9>: pop ebp 0x0804840e <+10>: ret Compiler options No optimizations enabled, just gcc -m32 -o test test.c ( -m32 because I'm on a 64 bit machine).

Automatic code deduplication of assembly language?

一曲冷凌霜 提交于 2019-12-03 13:29:54
I've been going through some Assembly Programming Videos to get a better understanding of how to manually optimize the *.s files left after compiling with gcc/g++ -S ... One of the topics covered was Refactoring Redundant Code that demonstrates how to move redundant code to its own labeled block ending with a ret and replacing it with a call . The example given in the video is 2 blocks containing: mov eax,power mul ebx mov power,eax inc count which it replaces with call CalculateNextPower and CalculateNextPower looks like: CalculateNextPower: mov eax,power mul ebx mov power,eax inc count ret

What is my compiler doing? (optimizing memcpy)

吃可爱长大的小学妹 提交于 2019-12-03 12:38:45
I'm compiling a bit of code using the following settings in VC++2010: /O2 /Ob2 /Oi /Ot However I'm having some trouble understanding some parts of the assembly generated, I have put some questions in the code as comments. Also, what prefetching distance is generally recommended on modern cpus? I can ofc test on my own cpu, but I was hoping for some value that will work well on a wider range of cpus. Maybe one could use dynamic prefetching distances? <--EDIT: Another thing I'm surprised about is that the compiler does not interleave in some form the movdqa and movntdq instructions? Since these

C++ constant folding a loop for prime numbers

╄→гoц情女王★ 提交于 2019-12-03 12:06:54
Having had a look at previous questions 1 , 2 , I was wondering if I can force the compiler to perform a constant folding for the following code which prints prime numbers. #include <iostream> using namespace std; inline bool is_prime(int n) { if(n<2) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } int main() { for(int i=0;i<20;i++) if(is_prime(i)) cout<<i<<endl; return 0; } And I build it via: g++ -O3 -S main.cpp -o main.asm As the result are a few: 2,3,5,7,11,13,17,19 I would like to force compiler look at the code similar to for(int x:{2,3,5,7,11,13,17,19})