[Ada] Optimize length checks generated for slice assignments

Pierre-Marie de Rodat derodat@adacore.com
Wed Jun 17 08:16:10 GMT 2020


The purpose of this change is to enhance Optimize_Length_Comparison
so that it optimizes the two length computations generated for the
length check required for an assignment of array slices.  It also
ensures that the computations generated as part of the optimization
are done without overflow checks, which is possible since they are
done in Long_Long_Integer and all quantities are 32-bit large.

The second part aligns the handling of the 'First and 'Last attributes
for constrained array types with the one for scalar types: they are
replaced with direct references to entities that are not discriminants,
which further helps to optimize the above length computations.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-17  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_First>:
	Replace it with a direct reference to an entity which is not a
	discriminant for constrained array types.  Add same condition
	for scalar types.
	<Attribute_Last>: Merge with above implementation.
	* exp_ch4.adb (Optimize_Length_Comparison): Be prepared for a
	second entity whose length is compared.  Rename Prepare_64 to
	Convert_To_Long_Long_Integer.  If the second entity is present,
	compute the difference of the 'First attributes and compare the
	sum of 'Last of the second entity with this difference against
	'Last of the first entity.  Add a special case when the 'First
	attributes are equal.  Suppress overflow checks in all cases.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 17399 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200617/b05292d9/attachment-0001.bin>


More information about the Gcc-patches mailing list