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] |
This patch optimizes 2**N to a shift in more contexts. Previously this optimization was applied only when 2**N appeared as the operand of a multiply or divide. Now it applies in other contexts as well. The following test program: function Pow2_Shift (B : Integer; N : Natural) return Natural is begin if B = 0 then return 2 ** N; elsif B = 1 then return 4 * 2 ** N; else return 1 * 2 ** N; end if; end Pow2_Shift; generates the following output with -gnatG: function pow2_shift (b : integer; n : natural) return natural is begin if b = 0 then [constraint_error when not (shift_left!(1, n) >= 0) "range check failed"] return natural(shift_left!(1, n)); elsif b = 1 then [constraint_error when not (shift_left!(4, n) >= 0) "range check failed"] return natural(shift_left!(4, n)); else [constraint_error when not (shift_left!(1, n) >= 0) "range check failed"] return natural(shift_left!(1, n)); end if; end pow2_shift; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-14 Robert Dewar <dewar@adacore.com> * exp_ch4.adb (Expand_N_Op_Expon): Optimize 2**N in stand alone context
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] |