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



Jakub Jelinek <jakub at gcc dot gnu.org> changed:



           What    |Removed                     |Added

----------------------------------------------------------------------------

  Attachment #29650|0                           |1

        is obsolete|                            |



--- Comment #21 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-12 
20:09:58 UTC ---

Created attachment 29657

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29657

gcc48-pr53265.patch



Updated patch that actually passed bootstrap/regtest.  Unfortunately, for fn4

and fn7 in the testcase to pass, I had to give up with only warning in

PROP_loops state, because the cunrolli pass optimizes those loops.



While it bootstrapped fine (with unwind-dw2.c fix I'll attach too), there were

some regressions, some -Waggressive-loop-optimizations warnings during

bootstrap/regtest and also with the additional debugging hack in various places

the number of iterations upper bound increased.



The regressions are:

../../gcc/ada/exp_ch7.adb:3540:11: warning: iteration 2147483646 invokes

undefined behavior [-Waggressive-loop-optimizations]

warning during x86_64 Ada build and:



+FAIL: gcc.dg/torture/pr49518.c  -O3 -fomit-frame-pointer  (test for excess

errors)

+FAIL: gcc.dg/torture/pr49518.c  -O3 -fomit-frame-pointer -funroll-loops  (test

for excess errors)

+FAIL: gcc.dg/torture/pr49518.c  -O3 -fomit-frame-pointer -funroll-all-loops

-finline-functions  (test for excess errors)

+FAIL: gcc.dg/torture/pr49518.c  -O3 -g  (test for excess errors)

+FAIL: g++.dg/opt/longbranch2.C -std=gnu++98 (test for excess errors)

+FAIL: g++.dg/opt/longbranch2.C -std=gnu++11 (test for excess errors)

+FAIL: libmudflap.c/fail37-frag.c (-O2) (test for excess errors)

+FAIL: libmudflap.c/fail37-frag.c (-O3) (test for excess errors)



(longbranch2.C only on i686, not on x86_64).  For fail32-frag.c, I believe we

just want to add asm ("" : "+r" (i)); into the loop to hide stuff from the

optimizers.



With the debugging hack, the cases of increasing number of iterations at the

end of estimate_numbers_of_iterations_loop are (except for pr53265.c, which of

course has tons of them):



64 ../../gcc/ada/exp_ch7.adb:3540 7ffffffd 0 ffffffff 0

{32,64} /usr/src/gcc/gcc/testsuite/gcc.dg/torture/pr49518.c:10 2 0 fffffffd 0

32 /usr/src/gcc/gcc/testsuite/g++.dg/opt/longbranch2.C:36 100 0 1ff 0

32 /usr/src/gcc/gcc/testsuite/g++.dg/opt/longbranch2.C:36 ff 0 1fe 0    

{32,64} /usr/src/gcc/gcc/testsuite/gfortran.dg/do_1.f90:10 9 0 a 0   

{32,64} /usr/src/gcc/gcc/testsuite/gfortran.dg/do_1.f90:16 4 0 5 0

{32,64} /usr/src/gcc/gcc/testsuite/gfortran.dg/do_1.f90:21 3 0 4 0

{32,64} /usr/src/gcc/libmudflap/testsuite/libmudflap.c/fail37-frag.c:15 4 0 5 0



In exp_ch7.adb it looks like pass ordering, cunrolli is run on dead code there,

*.copyrename2 has:

  [../../gcc/ada/exp_ch7.adb : 3540:11] ind.127_3 = 1;

  [../../gcc/ada/exp_ch7.adb : 3540:11] if (ind.127_3 > 1)

    goto <bb 3>;

  else

    goto <bb 6>;



  <bb 3>:

  # fent_39 = PHI <[../../gcc/ada/exp_ch7.adb : 3535:7] fent_2(2)>

  # j_40 = PHI <[../../gcc/ada/exp_ch7.adb : 3540:11] 1(2)>



  <bb 4>:

  # fent_6 = PHI <fent_39(3), [../../gcc/ada/exp_ch7.adb : 3541:10] fent_7(5)>

  # j_4 = PHI <j_40(3), [../../gcc/ada/exp_ch7.adb : 3540:11] j_5(5)>

  # DEBUG j => j_4

  # DEBUG fent => fent_6

  [../../gcc/ada/exp_ch7.adb : 3540:11] j_5 = j_4 + 1;

  [../../gcc/ada/exp_ch7.adb : 3540:11] # DEBUG j => j_5

  [../../gcc/ada/exp_ch7.adb : 3541:10] fent_7 = sinfo.next_entity (fent_6);

  [../../gcc/ada/exp_ch7.adb : 3541:10] # DEBUG fent => fent_7

  [../../gcc/ada/exp_ch7.adb : 3540:25] if (ind.127_3 != j_5)

    goto <bb 5>;

  else

    goto <bb 6>;



where both j and ind.127 are signed SImode vars.  number_of_latch_iterations

estimates the bound as 0xffffffff, signed overflow decreases that guess, but it

is really in dead code (something visible only through inlining though).

ccp2 immediately after cunrolli would fix this up, but that is too late.



For pr49518.c, I guess it is reasonable to warn, if the loop invariant

conditions are all such that it keeps looping, then the loop indeed triggers

undefined behavior.



Thoughts?

Reply via email to