AnsweredAssumed Answered

S12 unexpected code optimisation

Question asked by colin howard on Aug 30, 2006
Latest reply on Aug 31, 2006 by Alban Rampon
Hi

I am getting some puzzling optimisation from CodeWarrior HC12 4.5

In the following routine the optimiser decides to remove the second test of the resultant read from ESTAT. I get the "Removed dead code" message but I cannot see the rationale behind the optimisation (maybe I've been working too late!) After the code listing I have also shown the listing extract.

Any ideas?

Thanks
Colin

Code:
uint8 EE_Command(uint16* address, uint16 data, uint8 command){uint8 eeStatus;uint8 result = 0x00;*address = data;ECMD = command; ESTAT = ESTAT_CBEIF_MASK;eeStatus = ESTAT;if(eeStatus & ESTAT_PVIOL_MASK){ESTAT = ESTAT_PVIOL_MASK; result = ESTAT_PVIOL_MASK; }else if(eeStatus & ESTAT_ACCERR_MASK){ESTAT = ESTAT_ACCERR_MASK; // *** optimised outresult = ESTAT_ACCERR_MASK; // *** optimised out}else {while(!ESTAT_CCIF){// do nothing }}return result;}42: if(eeStatus & ESTAT_PVIOL_MASK)0017 8420 [1] ANDA #320019 2709 [3/1] BEQ *+11 ;abs = 002443: {44: ESTAT = ESTAT_PVIOL_MASK; 001b 8620 [1] LDAA #32001d 7a0000 [3] STAA _ESTAT45: result = ESTAT_PVIOL_MASK;0020 6a81 [2] STAA 1,SP46: }0022 2005 [3] BRA *+7 ;abs = 002947: else if(eeStatus & ESTAT_ACCERR_MASK)48: {49: ESTAT = ESTAT_ACCERR_MASK; 50: result = ESTAT_ACCERR_MASK;51: }52: else 53: {54: while(!ESTAT_CCIF)0024 1f000040fb [5] BRCLR _ESTAT,#64,*+0 ;abs = 002455: {56: // do nothing 57: }58: }59: 60: return result;0029 e681 [3] LDAB 1,SP61: }

 
(Alban formatted code for lisibility - Use SRC button)

Message Edited by Alban on 2006-08-30 03:36 PM

Outcomes