On Thu, Mar 21, 2019 at 9:25 AM Alexander Monakov <amona...@ispras.ru> wrote: > > On Thu, 21 Mar 2019, Richard Biener wrote: > > > Maybe an example would help. > > > > > > Consider this code: > > > > > > for (int i = start; i < limit; i++) { > > > foo(i * 5); > > > } > > > > > > Should GCC be entitled to turn it into > > > > > > int limit_tmp = i * 5; > > > for (int i = start * 5; i < limit_tmp; i += 5) { > > > foo(i); > > > } > > > > > > If you answered "Yes, GCC should be allowed to do this", would you > > > want a warning? And how many such warnings might there be in a typical > > > program? > > > > I assume i is signed int. Even then GCC may not do this unless it knows > > the loop is entered (start < limit). > > Additionally, the compiler needs to prove that 'foo' always returns normally > (i.e. cannot invoke exit/longjmp or such).
Ah, yes. Andrews example was probably meaning limit_tmp = limit * 5, not i * 5. Computing start * 5 is fine if the loop is entered. Richard. > > Alexander