2

I've have investigating the effect of __restricting certain pointers in a C++-code, when compiling it via the GCC-compiler.

It turned that not only the run-time remains quite the same, but the executable doesn't seem to have changed, the size in bytes is exactly the same as before.

My GCC-version is

gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)

and although it accepts this C++-extension when parsing, it does not seem to regard it when assembling the code. So there is either a reason, the compiler doesn't know how to use this semantic information, or processing this information is completly disabled.

The code performs a lot of number crunching, it would like to have it enabled for testing purposes. Can you help?

Mat
  • 202,337
  • 40
  • 393
  • 406
shuhalo
  • 5,732
  • 12
  • 43
  • 60
  • Without the code, it's really hard to say anything. It's possible that, with the way the code is written, the `__restrict` keyword doesn't buy you anything. There are cases (two pointers pointing to different types are assumed to never point at the same memory unless one of them is `char *`) in which it's just assumed anyway. – Omnifarious Aug 19 '10 at 15:00
  • The `restrict` keyword has a very specific effect on the generated assembly. You should use `objdump` or `gcc -S` to look at the assembly it's generating to see what the effect is. The size of your executable and run-time are poor benchmarks of its effect. – greyfade Aug 19 '10 at 15:01
  • The question is not yet, whether the knowledge of several arrays being disjoint does any help for the compiler, as the executables built are completely the same byte for byte. Therefore I guess the feature is disabled in the compiler itself. – shuhalo Aug 19 '10 at 15:13
  • @morgennebel - That may or may not be true. If you added the restrict keyword in places where it didn't help the optimizer, your compiled output isn't going to change at all, and your executable will indeed be the same byte-for-byte. I believe that gcc can pay attention to this keyword. I know the code is there because it also handles FORTRAN, and restrict is just how things are supposed to work in FORTRAN. – Omnifarious Aug 19 '10 at 23:51

1 Answers1

7

restrict qualifiers are basically a way for the user to help the compiler to perform certain aliasing-related optimizations. They will only have an effect if these optimization opportunities are already present in the code, so using restrict simply enables them in situations when the compiler previously had to use a "safer" (non-optimizing) code generation. In other contexts restrict will have no effect at all.

So, you added some restrict qualifiers to your code. But was any of them used in the context where they actually matter, i.e. where they actually give the compiler more freedom to optimize the code? If not, you are not supposed to expect your code to change.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • I employed it for several functions that assemble a matrix and solve a linear system. These process several arrays that represent nodal quantities and parameters and process it within a huge for loop. Hence I guess this information might be worth to know for the optimizer. – shuhalo Aug 19 '10 at 15:19