compiler-optimization

Can a conforming C# compiler optimize away a local (but unused) variable if it is the only strong reference to an object?

孤人 提交于 2019-12-22 03:37:10
问题 See also these related resources: Does the .NET garbage collector perform predictive analysis of code? (on Stack Overflow) WP7: When does GC Consider a Local Variable as Garbage (blog article on MSDN) In other words: Can an object referenced by a local variable be reclaimed before the variable goes out of scope (eg. because the variable is assigned, but then not used again), or is that object guaranteed to be ineligible for garbage collection until the variable goes out of scope? Let me

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

ぐ巨炮叔叔 提交于 2019-12-22 03:17:49
问题 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

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

戏子无情 提交于 2019-12-22 02:32:32
问题 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

Is there a technical reason that C# does not issue the “tail.” CIL instruction? [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-22 01:23:48
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why doesn't .net/C# eliminate tail recursion? Take the following C# code: using System; namespace TailTest { class MainClass { public static void Main (string[] args) { Counter(0); } static void Counter(int i) { Console.WriteLine(i); if (i < int.MaxValue) Counter(++i); } } } The C# compiler (mine anyway) will compile the Counter method into the following CIL: .method private static hidebysig default void Counter

simple compiler for optimization purposes

喜你入骨 提交于 2019-12-22 00:19:57
问题 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. 回答1: You might try: cucu: a compiler you can understand It is a simple C

Does profile-guided optimization done by compiler notably hurt cases not covered with profiling dataset?

☆樱花仙子☆ 提交于 2019-12-21 17:42:05
问题 This question is not specific to C++, AFAIK certain runtimes like Java RE can do profiled-guided optimization on the fly, I'm interested in that too. MSDN describes PGO like this: I instrument my program and run it under profiler, then the compiler uses data gathered by profiler to automatically reorganize branching and loops in such way that branch misprediction is reduced and most often run code is placed compactly to improve its locality Now obviously profiling result will depend on a

Compiler optimization causing the performance to slow down

泪湿孤枕 提交于 2019-12-21 17:24:01
问题 I have one strange problem. I have following piece of code: template<clss index, class policy> inline int CBase<index,policy>::func(const A& test_in, int* srcPtr ,int* dstPtr) { int width = test_in.width(); int height = test_in.height(); double d = 0.0; //here is the problem for(int y = 0; y < height; y++) { //Pointer initializations //multiplication involving y //ex: int z = someBigNumber*y + someOtherBigNumber; for(int x = 0; x < width; x++) { //multiplication involving x //ex: int z =

mtune and march when compiling in a docker image

烈酒焚心 提交于 2019-12-21 12:22:52
问题 When compiling in a docker image (i.e. in the dockerfile), what should march and mtune be set to? Note this is not about compiling in a running container, but compiling when the container is being built (e.g. building tools from source when the image is run). For example, currently when I run docker build and install R packages from source I get loads of (could be g++/gcc/f95 ...): g++ -std=gnu++14 [...] -O3 -march=native -mtune=native -fPIC [...] If I use native in an image built by

Are empty constructors always called in C++?

末鹿安然 提交于 2019-12-21 12:17:46
问题 I have a general question, that may be a little compiler-specific. I'm interested in the conditions under which a constructor will be called. Specifically, in release mode/builds optimised for speed , will a compiler-generated or empty constructor always be called when you instantiate an object? class NoConstructor { int member; }; class EmptyConstructor { int member; }; class InitConstructor { InitConstructor() : member(3) {} int member; }; int main(int argc, _TCHAR* argv[]) { NoConstructor*

Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?

限于喜欢 提交于 2019-12-21 06:45:22
问题 I am doing some numerical optimization on a scientific application. One thing I noticed is that GCC will optimize the call pow(a,2) by compiling it into a*a , but the call pow(a,6) is not optimized and will actually call the library function pow , which greatly slows down the performance. (In contrast, Intel C++ Compiler, executable icc , will eliminate the library call for pow(a,6) .) What I am curious about is that when I replaced pow(a,6) with a*a*a*a*a*a using GCC 4.5.1 and options " -O3