Interesting! Is that because it allows scenarios in which the compiler is not able to see/determine if the shared variable is used or not? And thus it keeps the loop to be safe?deltarho[1859] wrote:In the opening post replacewithCode: Select all
dim as ulongint i,j
and the loop is no longer optimized out.Code: Select all
dim as ulongint i dim shared as ulongint j
Compiled with -gen gcc -Wc -O3
Compiled reality
Re: Compiled reality
-
- Posts: 4308
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Compiled reality
I am sure that the compiler could be made to do that but I should not think that would come cheap.Provoni wrote:Is that because it allows scenarios in which the compiler is not able to see/determine if the shared variable is used or not?
I originally figured that there was a fair chance that the compiler would not interfere with a global scope. That was just a 'gut feeling' - no real grounds for supposing that. However, I think that there is more to it than that. It may be because we have put 'j' into the application's .data section but, again, I have no grounds for supposing that either.
Perhaps someone better acquainted with compilers can provide an answer.
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
Re: Compiled reality
Compilers are best at optimizing individual functions, and sometimes good at optimizing their immediate context. Compiler authors aim to make optimizations that are as close as possible to theoretically, deterministically proven not to cause harm. They don't always succeed. Sometimes, compilers will avoid optimizations that it can't predictably say will not have any effect on the programs.
Depending on how you write your code, there are PLENTY of optimizations that will be missed... Also, a compiler can only optimize so much. Well-written code goes much further.
Yes, individual algorithms can be greatly optimized with rearrangements and distribution of work between CPU and memory, but which algorithms and data structures used will ultimately have the biggest impact.
When you're working in something like C++, there isn't too much background processing going on to begin with. I think overall, optimization improves specific algorithms greatly, but not too much for overall application performance in many applications. Ex: If you use even a single slow library, that will be the biggest bottleneck.
Not to digress too much, but I'm seeing even C++ get support for patterns that make it easier to code. The real neat stuff won't be in C++ for another 5 - 10 years possibly, but the C++ roadmap is trending in the right direction. If C++ had moved faster in this way, I think a lot of modern, dynamic programming languages would be executing much faster and have different syntax and semantics.
Depending on how you write your code, there are PLENTY of optimizations that will be missed... Also, a compiler can only optimize so much. Well-written code goes much further.
Yes, individual algorithms can be greatly optimized with rearrangements and distribution of work between CPU and memory, but which algorithms and data structures used will ultimately have the biggest impact.
When you're working in something like C++, there isn't too much background processing going on to begin with. I think overall, optimization improves specific algorithms greatly, but not too much for overall application performance in many applications. Ex: If you use even a single slow library, that will be the biggest bottleneck.
Not to digress too much, but I'm seeing even C++ get support for patterns that make it easier to code. The real neat stuff won't be in C++ for another 5 - 10 years possibly, but the C++ roadmap is trending in the right direction. If C++ had moved faster in this way, I think a lot of modern, dynamic programming languages would be executing much faster and have different syntax and semantics.
-
- Posts: 4308
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Compiled reality
anonymous1337 wrote:Also, a compiler can only optimize so much. Well-written code goes much further.
Yep, we cannot "make a silk purse of a sow's ear".
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Compiled reality
Unless you accomplish to breed a silk sow. <grin>deltarho[1859] wrote:Yep, we cannot "make a silk purse of a sow's ear".
-
- Posts: 4308
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Compiled reality
Quite so and likely to be seen beneath a gaggle of low flying pigs.grindstone wrote:Unless you accomplish to breed a silk sow. <grin>