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

Robert Dubner <rdubner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |rdubner at gcc dot gnu.org
   Last reconfirmed|                            |2026-07-17
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rdubner at gcc dot 
gnu.org

--- Comment #2 from Robert Dubner <rdubner at gcc dot gnu.org> ---
Your analysis is exactly right.  We do COMPUTE badly.  We didn't know better at
the time, and so each step of a compute creates and uses temporary variables
and feeds them (as you note) to the general-purpose arithmetic routines.

On my x86_64 i9-14900K machine, which can bump its clock speed into the 5-6GHz
range, your program, as written, compiled with -O2, runs in about 0.900
seconds.

Rewritten thusly:
~~~~~~~~~~
       identification division.
       program-id. slowcomp5.
       data division.
       working-storage section.
       01  ws-i    pic s9(9)  usage comp-5.
       01  ws-n    pic s9(9)  usage comp-5 value 5000000.
       01  ws-a    pic s9(9)  usage comp-5.
       01  ws-b    pic s9(9)  usage comp-5.
       01  ws-x    pic s9(18) usage comp-5.
       procedure division.
           move 0 to ws-x
           perform varying ws-i from 1 by 1 until ws-i > ws-n
      *>     compute ws-a = 2 * ws-i - 1
           multiply ws-i by 2 giving ws-b
           subtract 1 from ws-a
      *>     compute ws-b = ws-i * ws-a
           multiply ws-i by ws-a giving ws-b
      *>     compute ws-x = ws-x + ws-b
           add ws-b to ws-x
           end-perform
           display ws-x
           goback.
~~~~~~~~~~
the execution time is about 0.010 seconds.

Some months back we started a refactoring of COMPUTE where the parser creates
an Reverse Polish representation of the expression.  With that, I'll be able to
create a GENERIC representation that will get lowered.  But we got sidetracked.
 It's near the top of the list of things we want to get back to.

Thank you for the work you are doing.

Reply via email to