[Ada] Streamline comparison for equality of 2-element arrays
commit1dd3915be108e6dcd7adfa01de6096419092a5de
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 19 Sep 2019 08:13:29 +0000 (19 08:13 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 19 Sep 2019 08:13:29 +0000 (19 08:13 +0000)
tree42ffcfdfd44bf6e5926e9edee4bc052bc0357912
parentc4f372c54f24fd24f1092fb6a09c31c7733ce8cc
[Ada] Streamline comparison for equality of 2-element arrays

In the general case, the comparison for equality of array objects is
implemented by a local function that contains, among other things, a
loop running over the elements, comparing them one by one and exiting
as soon as an element is not the same in the two array objects.

For the specific case of constrained 2-element arrays, this is rather
heavy and unnecessarily obfuscates the control flow of the program,
so this change implements a simple conjunction of comparisons for it.

Running these commands:

  gcc -c p.ads -O -gnatD
  grep loop p.ads.dg

On the following sources:

package P is

  type Rec is record
    Re : Float;
    Im : Float;
  end record;

  type Arr is array (1 .. 2) of Rec;

  function Equal (A, B : Arr) return Boolean is (A = B);

end P;

Should execute silently.

2019-09-19  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* exp_ch4.adb (Expand_Array_Equality): If optimization is
enabled, generate a simple conjunction of comparisons for the
specific case of constrained 1-dimensional 2-element arrays.
Fix formatting.

From-SVN: r275941
gcc/ada/ChangeLog
gcc/ada/exp_ch4.adb