This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Reduce use of N_Reference nodes in generated code


This is an internal optimization that reduces the number of cases
in which we generate N_Reference nodes. Generally has no effect
on functional behavior, but the following test:

     1. function StrangeRef (A, B : Integer) return Integer is
     2.    X : Integer;
     3. begin
     4.    X := Integer'Max ((if A > 4 then B else 15), B);
     5.    return X;
     6. end StrangeRef;

compiled with -gnatG and -gnatd.u can be used to see that we do properly
optimize this case and avoid generating an N_Reference node which is what
we used to do:

Source recreated from tree for Strangeref (body)

function strangeref (a : integer; b : integer) return integer is
   x : integer;
begin
   R1b : constant integer := (if a > 4 then integer(b) else 15);
   x := (if (R1b) >= b then (R1b) else integer(b));
   return x;
end strangeref;

Previously R1b generated an N_Reference node

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

2014-02-18  Robert Dewar  <dewar@adacore.com>

	* exp_attr.adb: Minor reformatting.
	* exp_ch4.ads, exp_ch4.adb (Expand_N_Reference): New procedure.
	* exp_util.adb (Remove_Side_Effects): Add conditional expressions
	as another case where we don't generate N_Reference nodes for
	primitive types.
	* expander.adb (Expand): Add call to Expand_N_Reference.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]