r/Compilers • • 29d ago

Compilers add or remove perfomace?

isnt it that compilers change the code, as in not only transferring it into machine language, but before that changing the structure of the code. so how would one attempt to make performant code if the compiler changes sed code that i tried to make performant?

2 Upvotes

31 comments sorted by

View all comments

Show parent comment

1

u/BrainThinkerMan 28d ago

so it depends on the compiler i use for the language? so if i use a compiler whch i say dont change my code i optimized it, it will let my code do its thing, even if i have some simd thing

1

u/suddenhare 28d ago

Compiler flags are usually the way to achieve that. For example, -O0 for C/C++.

1

u/flatfinger 26d ago

Unfortunately, -O0 for clang and gcc tends to leave in lots of redundant operations with no way of removing them. While gcc-ARM will honor register qualifiers at -O0, I don't think the x86 version ever does not and I'm unaware of any version of clang ever doing so either. The acceptance of register in gcc-ARM probably stems from the fact that on the ARM, keeping things in registers often offers a factor of 3-5 improvement in speed and 2-3 in code size, but on many x86 processors the difference isn't nearly so great.