Hi All, I have found an issue related with the condition register usage, while migrating to GCC from DIAB compiler. The RTOS used is AMX and the platform is PowerPC. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= if (argVal < MACRO_VALUE) // exp-1 { cmplwi cr4, r3, 0x1 bgt+ cr4, 0xaabb .... .... } ... x = os_wrapper_fn(); // Modifies CR4 ... if (argVal < MACRO_VALUE) // exp-2 { bgt+ cr4, 0xccdd .... .... } =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1. The comparison result of expression "(argVal < MACRO_VALUE)" is stored in CR4 initially (exp-1). Since the same expression is used again (exp-2) and the 'argVal' is not modified in between these expressions, GCC does not re-evaluate the expression, instead uses the already evaluated result from CR4 for branch decision. But in between these two comparison statements, there is a system call where the CR4 register is used for expression evaluation. So when the CR4 register is reused in the second if statement (exp-2), the evaluation result goes wrong. The above comparison is made in several places w/o any changes in 'argVal' value, so it seems to be a fairly obvious and valid optimisation to take result of "(argVal < MACRO_VALUE)" into CR4 and keep it there and just branch on it later. Diab does not do that but gcc does. My concern is if GCC assumes 'CR4' is preserved across function calls, and e.g. my RTOS call would not preserve it. I have tried using volatile qualifier on 'argVal' which stops optimization and thus comparison expression is evaluated again instead of reusing the result from CR4. In this case, things go fine, but I still have this concern that there can be many such places in code where this issue can come up. So I am thinking of the following options: Option (1) Not to use CR1..CR3, by taking those out of GCC use, which limits the optimization potential. Can anyone please advise if there is any option to restrict the CR usage? Option (2) To tell GCC that each of the OS calls modifies condition code register.Is there a pragma to define registers which an external function will trash? Or do we have any other option to solve this issue? Can anyone please help? Thanks-in-advance. -- View this message in context: http://old.nabble.com/Reg%3A-Restricting-optimization-and-CR-register-usage-tp29933073p29933073.html Sent from the gcc - Help mailing list archive at Nabble.com.