[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