This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR/7896: [H8300] C compiler generates wrong code


This code looks correct:

                 _bla:
                   push.l  er4
                   mov.w   r0,r4
                   subs    #1,er4
                   beq     .L7
                 .L5:
                   mov.l   er4,@-er7
                   mov.l   #.LC0,er2
                   mov.l   er2,@-er7
                   mov.l   @__impure_ptr,er2
                   mov.l   @(8,er2),er0
                   jsr     @_fprintf
                   adds    #4,er7
                   adds    #4,er7
                   mov.w   r4,r2
                   subs    #1,er4
                   bne     .L5
                 .L7:
                   pop.l   er4
                   rts

The value of er4 is tested before er4 is decremented. 
The instruction:

	subs	#1,er4

does not affect the Z flag according to my H8/300H series manual
page 180.

So therefore the Z flag is set by the previous:

	mov.w	r0,r4

or
	mov.w	r4,r2

and therefore the code seems to be correct.

Toshi



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]