[Bug tree-optimization/40679] Optimizer handles loops with volatiles and post-incr. wrong

bastian dot schick at sciopta dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 8 13:06:00 GMT 2009



------- Comment #8 from bastian dot schick at sciopta dot com  2009-07-08 13:06 -------
(In reply to comment #6)
> (In reply to comment #2)
> > Replacing *tbl++ by tbl[i] gives this ARM code:
> > .L2:
> >         mov     r3, #10
> >         str     r3, [r2], #4
> >         cmp     r2, #0
> >         bne     .L2
> >         bx      lr
> > 
> > See, gcc knows about the wrapping but still the *tbl++ version misses the
> > end-condition which is the bug.
> 
> The difference is that in the tbl[i] version there will not be a wraparound at
> runtime because &tbl[i] for i == 64 is never computed, while in the *tbl++
> version the iteration with i == 63 will do tbl++ moving tbl from -4U to 0
> before the loop termination test, which triggers undefined behaviour.

Ok fine, but why does it generate correct code if not using volatile for the
pointer ?!
        mvn     r2, #251
.L2:
        mov     r3, #10
        str     r3, [r2, #-4]
        add     r2, r2, #4
        cmp     r2, #4
        bne     .L2
        bx      lr
Strange, no post-increment code is generated.
The 68k version still uses post-increment and voilà, endless-loop.

Also see the code for the tbl[i] version, the pointer still wraps.

I suspect following: The test for 0 is removed maybe because the post-increment
is defined to change flags( which it isn't). Since there is no test, the next
optimization changes a "jump not zero" to an "jump always".


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40679



More information about the Gcc-bugs mailing list