[m-users.] Best way to implement constants ?

Julien Fischer jfischer at opturion.com
Fri Aug 18 20:00:59 AEST 2023



On Fri, 18 Aug 2023, Zoltan Somogyi wrote:

> On 2023-08-18 11:37 +02:00 CEST, "Julien Fischer" <jfischer at opturion.com> wrote:
>> At -O3 and above the Mercury compiler will (generally) evaluate a
>> variety of operations (see compiler/const_prop.m for details).
>> Float division is included in those operations
>
> Actually, constant propagation is not enabled automatically at any
> optimization level; you have to enable manually, with --optimize-constant-propagation.

When and why did that change?  Here's the definition of -O3 from Mercury 14.01

     opt_level(3, _, [
         optimize_saved_vars_const   - bool(yes),
         optimize_unused_args        -   bool(yes),
         optimize_higher_order       -   bool(yes),
         deforestation               -   bool(yes),
         local_constraint_propagation -  bool(yes),
         constant_propagation        -   bool(yes),
         ^^^^^^^^^^^^^^^^^^^^

         optimize_reassign           -   bool(yes),
         % Disabled until a bug in extras/trailed_update/var.m is resolved.
         % introduce_accumulators    -   bool(yes),
         optimize_repeat             -   int(4)
     ]).

It was enabled at -O3 back then.

> What is enabled at -O3 is *constraint* propagation, which I also
> misread as *constant* propagation at first :-(
> I will add constant propagation to -O3.

I would argue that at least some of its work, notably string
concatenation, ought to be done at -O2.

Julien.


More information about the users mailing list