[m-rev.] for review: --split-switch-arms

Zoltan Somogyi zoltan.somogyi at runbox.com
Tue Jul 25 03:04:25 AEST 2023


On 2023-07-24 15:54 +02:00 CEST, "Julien Fischer" <jfischer at opturion.com> wrote:
> I suggest adding the rationale for performing this transformation here
> (i.e. from the log message).

I added the following text to the end of the module comment for
split_switch_arms.m. I also followed your other suggestions.

% The code resulting from the above steps will include some code duplication
% (most of the pieces of code denoted by <code to handle ...> in the example
% above would be duplicated), but it will need to execute fewer transfers
% of control. This is worthwhile because
%
% - the branch instructions used to implement switches are hard to predict
%   unless most paths through the nested switches are rarely if ever taken, and
%
% - the pipeline breaks caused by branches that are not correctly predicted
%   are one of the two major contributors to the runtime of Mercury programs.
%   (The other major contributors are data cache misses.)
%
% Nevertheless, the main point of this transformation is not performance,
% since the transformation performed by this module could also be done
% manually by humans. Instead, the main point is that having the transformatio
% done by a machine is better from a software engineering point of view.
% One software engineering advantage is that the compiler can do the
% transformation more quickly, more cheaply, and more reliably than
% programmers can. Another advantage is that it allows programmers to maintain
% the pre-transform version of the code. The pre-transform version may be
% clearer and easier to maintain than the post-transform version, due to
% the code duplication required by the transform.

> That looks fine otherwise.

Thanks for the review.

Zoltan.


More information about the reviews mailing list