I have some code that I was debugging and I noticed that the compiler (MIPS gcc-4.7.2) is not pre-calculating certain values that I would expect to just a static value in memory. Here's the crux of the code that is causing what I am seeing:
#define SAMPLES_DATA 500
#define VECTORX 12
#define VECTORY 18
(int *)calloc(SAMPLES_DATA * VECTORX * VECTORY, sizeof(int));
In the assembly, I see that these values are multiplied as (500*12*18) instead of a static value of 108000. This is only an issue because I have some code that runs in realtime where these defines are used to calculate the offsets into an array and the same behavior is seen. I only noticed because the time to write to memory was taking much longer than expected on the hardware. I currently have a "hot fix" that is a function that uses assembly, but I'd rather not push that into production.
Is this standard gcc compiler behavior? If so, is there some way to force or create a construction that precomputes these static multiplication values?
edit: I'm compiling with -O2; however, the build chain is huge. I don't see anything on the commands being generated by the Makefile that are unusual.
edit: The issue seems to not be present when gcc 5 is used. Whatever is causing my issue, seems to not carry on to later versions.