https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83262

--- Comment #13 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(In reply to anlauf from comment #11)
> (In reply to Thomas Koenig from comment #9)
> > Created attachment 64471 [details]
> > Updated test case
> > 
> > Here's an update on the test case.
> 
> You may want to apply:
> 
> --- asdf.f90.orig       2026-05-16 16:07:33.523572145 +0200
> +++ asdf.f90    2026-05-16 16:11:51.443302464 +0200
> @@ -204,7 +204,7 @@
>  
>           do i = 1,N 
>              
> -            key = mod(n,10) + 1
> +            key = mod(i,10) + 1
>  
>              if ( key .eq. 1 ) then 
>                 ss = ss + dble(12)*x1*dble((-1)**key) 
> @@ -278,7 +278,7 @@
>  
>           do i = 1,N 
>              
> -            key = mod(n,10) + 1
> +            key = mod(i,10) + 1
>  
>              if      ( key .eq. 1 ) then 
>                 ss = ss + dble(12)*x1*dble((-1)**key)

Ah, I missed those. Thanks for pointing these out.

Now, timings are:

$ gfortran -O1 asdf.f90 && ./a.out 100000000 200000000 300000000
 Number of input arguments:            3
          GOTO: n =100000000, ss = 0.4321400E+10, time =    0.106 (s)
   SELECT CASE: n =100000000, ss = 0.4321400E+10, time =    0.185 (s)
       IF-Goto: n =100000000, ss = 0.4321400E+10, time =    0.091 (s)
     IF-noGoto: n =100000000, ss = 0.4321400E+10, time =    0.185 (s)
       IF-ELSE: n =100000000, ss = 0.4321400E+10, time =    0.185 (s)

          GOTO: n =200000000, ss = 0.8642800E+10, time =    0.210 (s)
   SELECT CASE: n =200000000, ss = 0.8642800E+10, time =    0.374 (s)
       IF-Goto: n =200000000, ss = 0.8642800E+10, time =    0.182 (s)
     IF-noGoto: n =200000000, ss = 0.8642800E+10, time =    0.369 (s)
       IF-ELSE: n =200000000, ss = 0.8642800E+10, time =    0.369 (s)

          GOTO: n =300000000, ss = 0.1296420E+11, time =    0.316 (s)
   SELECT CASE: n =300000000, ss = 0.1296420E+11, time =    0.554 (s)
       IF-Goto: n =300000000, ss = 0.1296420E+11, time =    0.273 (s)
     IF-noGoto: n =300000000, ss = 0.1296420E+11, time =    0.554 (s)
       IF-ELSE: n =300000000, ss = 0.1296420E+11, time =    0.554 (s)

           GOTO costs totally     0.631 (s)
    SELECT CASE costs totally     1.112 (s)
        IF-Goto costs totally     0.546 (s)
      IF-noGoto costs totally     1.108 (s)
        IF-ELSE costs totally     1.108 (s)


$ gfortran -O2 asdf.f90 && ./a.out 100000000 200000000 300000000
 Number of input arguments:            3
          GOTO: n =100000000, ss = 0.4321400E+10, time =    0.133 (s)
   SELECT CASE: n =100000000, ss = 0.4321400E+10, time =    0.126 (s)
       IF-Goto: n =100000000, ss = 0.4321400E+10, time =    0.145 (s)
     IF-noGoto: n =100000000, ss = 0.4321400E+10, time =    0.143 (s)
       IF-ELSE: n =100000000, ss = 0.4321400E+10, time =    0.142 (s)

          GOTO: n =200000000, ss = 0.8642800E+10, time =    0.264 (s)
   SELECT CASE: n =200000000, ss = 0.8642800E+10, time =    0.253 (s)
       IF-Goto: n =200000000, ss = 0.8642800E+10, time =    0.291 (s)
     IF-noGoto: n =200000000, ss = 0.8642800E+10, time =    0.286 (s)
       IF-ELSE: n =200000000, ss = 0.8642800E+10, time =    0.287 (s)

          GOTO: n =300000000, ss = 0.1296420E+11, time =    0.396 (s)
   SELECT CASE: n =300000000, ss = 0.1296420E+11, time =    0.380 (s)
       IF-Goto: n =300000000, ss = 0.1296420E+11, time =    0.436 (s)
     IF-noGoto: n =300000000, ss = 0.1296420E+11, time =    0.427 (s)
       IF-ELSE: n =300000000, ss = 0.1296420E+11, time =    0.429 (s)

           GOTO costs totally     0.793 (s)
    SELECT CASE costs totally     0.760 (s)
        IF-Goto costs totally     0.872 (s)
      IF-noGoto costs totally     0.856 (s)
        IF-ELSE costs totally     0.857 (s)
    Total time:    4.138 (s)

so the IF-Goto version is significantly faster than anything else.
That is interesting.:

Reply via email to