top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to disable optimization for particular assignment statements?

+5 votes
584 views

I have a C code like this:

int foo(void)
{ 
 int phase;
 . . .
 phase = 1;
 phase = 2;
 phase = 3;
 . . .
}

In case of -O0 gcc generates machine instructions for every assignment 'phase = ...'. But in case of -O2 gcc does not generate instructions for some assignments. Of course, this is correct. However, is there any way to tell gcc that 'phase' object is inspected by another thread, so it should not remove such statements?

posted Nov 21, 2013 by Amit Parthsarthi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Check with these two and see Assembly code
  gcc -c -g -Wa,-a,-ad test.c > test1.lst // Deafault optimization
  gcc -O2 -c -g -Wa,-a,-ad test.c > test2.lst //O2  optimization


and u can check with changing the type of variable also ..like changing to volatile.

2 Answers

+2 votes

Define the variable as volatile.

answer Nov 21, 2013 by Naveena Garg
+1 vote

Basic rule of thumb: if code is not thread-safe, adding volatile will never make it thread-safe. That rule of thumb applies here. Adding volatile will not work, because it will not make the changes to the value visible to other processors.

http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

Yes, if you have decided that this is what you really want to do, using the atomic (or sync) builtins is the only viable approach (my thoughts)

answer Nov 22, 2013 by anonymous
Similar Questions
0 votes

I am looking for detailed description of optimization flags that are provided by GCC compiler ?

+1 vote

My current compiler settings are

arm-none-eabi-gcc -Wall -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -fshort-double-mcpu=cortex-m4 -mthumb -Qn -Os -finstrument-functions -mlong-calls -c temp.c -o temp.o
so on for temp1, temp2... Etc

I am compiling multiple C files. and linker settings are

ld -r temp.o -o one.o
so on for temp1, temp2... Etc

I am linking multiple .O files. Also I am using linker script i.e link.txt (invoked externally as below)

ld -cref -Map map.txt -S -T link.txt -temp.o -lm -lc -lgcc
arm-none-eabi-gcc -Wall sample.o -O Firmware.abs

Now, At output I get .abs file of 140KB.

My Questions are
1. How to optimize (reduce size of .abs) by using compiler or linker specific options?
2. There are Number of NOT used global variables and Blank Function Calls in my C files (NO Dead Code!!!!). Is it possible to perform some link time optimization.
3. Please Elaborate as I am new to this, I have referred sites, gcc help and tried some "lto" options but NO reduction is size.
4. I also tried using -fdata-sections -ffunction-sections
But It has INCREASED my firmware.abs file size from KB to MB (yes it is MB!!!!) I also wondered WHY?
I am using codesourcery arm toolchain evaluation. It has gcc version 4.5.2

+5 votes

GCC is stripping the object file when nothing from the file is being used anywhere in the executable (even -o0 does nor help). We have to disable this feature of linker g++. could any one please help us to resolve this issue??

+2 votes

I want to use some loop optimizations. I have build GCC-4.8.1 using gmp 5.1.3, mpfr 3.1.2, mpc 1.0.1, cloog 0.18.0 and isl 0.11.1. I tried optimization flags -floop-interchange and -floop-block. I don't find any changes in the optimized code.

Are graphite loop transforms implemented in GCC-4.8.1. Should I configure and build GCC in a different way.

+2 votes

As per spec T store Ue Context timer is used so that if with in this time period RLF occuring and applying rrc connection re establishment to source then Too early handover counted.

At what time we should start T store UE Context timer at target ...

...