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

2009-07-08 Thread ramana at gcc dot gnu dot org


--- Comment #5 from ramana at gcc dot gnu dot org  2009-07-08 09:12 ---
Richi,

Can you comment on this one ?

Ramana


-- 

ramana at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu dot
   ||org
  Component|rtl-optimization|tree-optimization


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



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

2009-07-08 Thread mikpe at it dot uu dot se


--- Comment #6 from mikpe at it dot uu dot se  2009-07-08 09:59 ---
(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.

And the issue is not ARM, the same infinite loop occurs for e.g. target i686.


-- 


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



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

2009-07-08 Thread rguenth at gcc dot gnu dot org


--- Comment #7 from rguenth at gcc dot gnu dot org  2009-07-08 10:10 ---
Indeed the overflow invokes undefined behavior.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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



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

2009-07-08 Thread bastian dot schick at sciopta dot com


--- 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



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

2009-07-08 Thread rguenth at gcc dot gnu dot org


--- Comment #9 from rguenth at gcc dot gnu dot org  2009-07-08 13:11 ---
induction variable optimization is different w/o volatile.


-- 


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