This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TI v20.2.5.LTS optimizer skips comparison

When running the programming example for the EEPROM of Tivaware with compiler optimization on it skips some important code.

e.g. in this code example line 22-27 are skiped when debugging and the variable ui32EEPROMInit does not get initialized at all.:

uint32_t ui32EEPROMInit;
uint32_t pui32Data[2];
uint32_t pui32Read[2];
//
// Enable the EEPROM module.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
//
// Wait for the EEPROM module to be ready.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EEPROM0))
{
}
//
// Wait for the EEPROM Initialization to complete
//
ui32EEPROMInit = EEPROMInit();
//
// Check if the EEPROM Initialization returned an error
// and inform the application
//
if(ui32EEPROMInit != EEPROM_INIT_OK)
{
while(1)
{
}
}
//
// Program some data into the EEPROM at address 0x400.
//
pui32Data[0] = 0x12345678;
pui32Data[1] = 0x56789abc;
EEPROMProgram(pui32Data, 0x400, sizeof(pui32Data));
//
// Read it back.
//
EEPROMRead(pui32Read, 0x400, sizeof(pui32Read));

What is happening here?

  • Hi,

      You are saying code between 22-27 are optimized out by the compiler when you turn on optimization but without optimization, the 22-27 are there. Is that correct? Can you look at the disassembly and confirm that after line 17 is executed, the processor continues to line 31 without executing code between line 22-27. You can use single step in the disassembly window to step through code. Normally, if you turn on optimization, you may see the code jump around as you single step the C code. This is normal because the optimized code is no longer line to line matching the symbols. But if you say the code is completely gone then that is a different question. Once you confirm the observation, I can forward your question to our compiler expert. Please also expect delay in response as this week has a major US public holiday. 

  • Thanks for the quick answer. In the disassembly only the variable is not initialized but the comparison takes place directly. That's why the debugger jumps over it in the single step.