Skip to main content

Questions tagged [compiler-optimization]

Compiler optimization involves adapting a compiler to reduce run-time or object size or both. This can be accomplished using compiler arguments (i.e. CFLAGS, LDFLAGS), compiler plugins (DEHYDRA for instance) or direct modifications to the compiler (such as modifying source code).

compiler-optimization
1 vote
1 answer
74 views

Side effects of constructing an explicitly unused object

Say I have a struct that provides a method that does some work (has useful side effects) and then returns an instance of itself. Do I have to use that instance somehow in order to guarantee that the ...
gstukelj's user avatar
  • 2,471
0 votes
0 answers
22 views

Different execution times for the same code

I'm working with the Texas Instruments (TI) RM57L843 microcontroller, where I'm observing the execution time of a for loop that performs matrix multiplication. I compiled the same code using TI's ...
Dan's user avatar
  • 1
0 votes
1 answer
21 views

Does LLVM iterate over blocks in a fixed order?

I am using LLVM to iterator basic blocks by for (const Function &F : *M) for (const BasicBlock &BB : F) for (const Instruction &I : BB){ ...... } I want to know: ...
Student Popper's user avatar
3 votes
0 answers
139 views

GCC optimizes x + n > y as x + (n-1) >= y?

In general, the program extern int x, y; int main() { return x + N > y; } is optimized into something akin to x + N-1 >= y for some given N. Example below. Am I reading the assembly right? ...
b44ken's user avatar
  • 31
0 votes
1 answer
76 views

How can a compiler perform whole code optimizations if most code are in the form of static libraries?

It's basically the title, but here is some context: Recently I've been trying to link a C library to a D main in WASM, and successfully produced "hello" to browser console (yay). This ...
Matheus de Moraes Peixoto's user avatar
1 vote
1 answer
145 views

Why is the computation speed of double in the Eigen library 3 times faster than that of float?

Here is my code. I created a set of matrix and vector multiplications using double type, and another set using float type. Both sets of multiplications are executed 3 million times in a for loop, and ...
zymaster's user avatar
0 votes
2 answers
157 views

Is there any way to explicitly tell compiler to stop optimization

Linux, C, GCC, ARM (Allwinner H3). Is it possible to get the following equivalent functionality (pseudocode): #pragma optimizations-stop #pragma registers-flush a=10; while(*b != 0) c++; if(a == 0) { ...
Anonymous's user avatar
  • 629
0 votes
1 answer
112 views

compiler optimization issue / variable has wrong value

I define variables as volatile sig_atomic_t v1; volatile int v2; Then in one process (thread) perform v1 = false; v2 = 0; ... v2 = (some_var); v1 = true; and in another process (thread) while(!v1) { ...
Anonymous's user avatar
  • 629
-2 votes
1 answer
76 views

Arithmetic error caused by -O3 option on g++ [duplicate]

I have the following (very simple) code: #include <cstdint> #include <iostream> #include <vector> int main(void) { std::vector<int64_t> result; int64_t seed = ...
marom's user avatar
  • 5,190
0 votes
1 answer
159 views

Are bitwise operators faster than logical operators [duplicate]

Should one expect that flag = (age < 0) | (age > 100) will execute faster than flag = (age < 0) || (age > 100) because the control flow in the || operator slows down instruction ...
Brad Bell's user avatar
2 votes
2 answers
76 views

tail call optimization with arguments on stack and callee with more arguments than caller

I have been writing a compiler and have discussed this situation with a colleague. In the most general case, suppose you have your arguments on the stack (once argument registers are exhausted). If ...
user129393192's user avatar
0 votes
3 answers
102 views

Extern (global) variable not optimized out

Why does not GCC compiler optimize out variable foo entirely? it can reason that it will never return from an infinite loop and thus there is no possibility of this variable being used in any other ...
user1806687's user avatar
-1 votes
1 answer
52 views

Control optimization in V8's TurboFan

I'm studying some internals of V8's TurboFan and came across this slide: Original slide. This diagram shows a branch that is removed during control optimization, resulting in a direct connection to a &...
Beginner's user avatar
1 vote
1 answer
110 views

Why __restrict often doesn't give optimization as expected?

#include <iostream> #include <chrono> void foo(int* a, int* b) { *a+=1; *b+=1; *a+=1; } void goo(int* __restrict a, int* b) { *a+=1; *b+=1; *a+=1; } void measure() { int x ...
Hayk's user avatar
  • 49
6 votes
1 answer
209 views

Why does this ternary generate more Assembly than an equivalent if?

So someone on a forum asked why this C function (which I added const and restrict to, just in case): void foo(int *const restrict dest, const int *const restrict source) { *dest = (*source != -1) ?...
MyNameIsTrez's user avatar

15 30 50 per page
1
2 3 4 5
220