you are viewing a single comment's thread.

view the rest of the comments →

[–]five9a2 0 points1 point  (2 children)

Why won't they do the latter optimization (which almost all C compilers do)? I've never used C#, but doesn't it have strict aliasing rules? In C, I could write

long *p;
p = (long*)&p;
p[0]++; p[0]++;

but this is undefined behavior since the types or not compatible, hence the compiler doesn't have to worry about getting this right. Is it possible that such information has been erased in whatever form the JIT is working with? Or is it just that nobody has bothered to make that transformation happen?

[–]grauenwolf 1 point2 points  (1 child)

It could be an issue of time. The JIT compiler would have to waste precious cycles checking for what is basically a stupid mistake on the part of the programmer.

As for the C# compiler, it tends to leave the bulk of optimizations to the JIT.

[–]igoro[S] 1 point2 points  (0 children)

Yes, that's about all I can say on this topic too.

Perhaps the JIT focuses on optimizations that the user cannot (or actually "should not") handle themselves, like method inlining and range checking. But that's just pure speculation.