#2008 no renown value after pointer changes.

closed-fixed
nobody
5
2013-05-25
2012-04-11
Sergey
No

Simple demo:
------------------------------------------------------------------------------------------------------
SDCC revision 7520 (other revisoins has same effect, optimisation-independently)

;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.1.4 #7520 (Mar 31 2012) (MINGW32)
; This file was generated Fri Apr 06 04:20:22 2012
;--------------------------------------------------------
.module I2C_DBGN
.optsdcc -mmcs51 --model-small

Source code:

void Compl8b (__idata U8 *p8) //__reentrant
{
*p8 = ~(*p8);
p8++;
*p8 = ~(*p8);
p8++;
*p8 = ~(*p8);
p8++;
*p8 = ~(*p8);
p8++;
(*(p8)) = ~(*(p8));
p8++;
(*(p8)) = ~(*(p8));
p8++;
(*(p8)) = ~(*(p8));
p8++;
(*(p8)) = ~(*(p8));
p8++;
}

Asm output:
NO variable load after pointer changes!!
See below:

;------------------------------------------------------------
;Allocation info for local variables in function 'Compl8b'
;------------------------------------------------------------
;p8 Allocated to registers r1
;------------------------------------------------------------
G$Compl8b$0$0 ==.
C$I2C_DBGN.c$4746$1$439 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4746: void Compl8b (__idata U8 *p8) //__reentrant
; -----------------------------------------
; function Compl8b
; -----------------------------------------
_Compl8b:
push ar7
push ar1
mov r1,dpl
C$I2C_DBGN.c$4748$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4748: *p8 = ~(*p8);
mov a,@r1
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4749$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4749: p8++;
C$I2C_DBGN.c$4750$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4750: *p8 = ~(*p8);
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4751$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4751: p8++;
C$I2C_DBGN.c$4752$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4752: *p8 = ~(*p8);
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4753$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4753: p8++;
C$I2C_DBGN.c$4754$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4754: *p8 = ~(*p8);
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4755$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4755: p8++;
C$I2C_DBGN.c$4756$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4756: (*(p8)) = ~(*(p8));
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4757$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4757: p8++;
C$I2C_DBGN.c$4758$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4758: (*(p8)) = ~(*(p8));
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4759$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4759: p8++;
C$I2C_DBGN.c$4760$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4760: (*(p8)) = ~(*(p8));
mov a,r7
cpl a
mov r7,a
mov @r1,a
inc r1
C$I2C_DBGN.c$4761$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4761: p8++;
C$I2C_DBGN.c$4762$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4762: (*(p8)) = ~(*(p8));
mov a,r7
cpl a
mov @r1,a
C$I2C_DBGN.c$4763$1$446 ==.
; C:\\PC104_T1\\I2C_DBGN.c:4763: p8++;
pop ar1
pop ar7
C$I2C_DBGN.c$4764$1$446 ==.
XG$Compl8b$0$0 ==.
ret
; eliminated unneeded push/pop ar0
------------------------------------------------------------------------

Discussion

  • Erik Petrich
    Erik Petrich
    2012-04-11

    • labels: 355283 --> C-Front End
    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Erik Petrich
    Erik Petrich
    2012-04-11

    This really surprised me.

    Fixed in revision #7559.

     
  • Sergey
    Sergey
    2012-04-11

    Thanks you.
    If you will, I can send some thinks about register-mapping and operation pattern optimization.
    (Computer science, closely, system programming was my first education, therefore I slightly known this topic, and wrote mini-Pascal compiler for specific processor)