[Ada] Streamline comparison for equality of 2-element arrays
Pierre-Marie de Rodat
derodat@adacore.com
Thu Sep 19 13:28:00 GMT 2019
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.
Tested on x86_64-pc-linux-gnu, committed on trunk
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 5408 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190919/fda02e90/attachment.bin>
More information about the Gcc-patches
mailing list