From: Bob Duff Date: Wed, 20 Aug 2008 14:27:50 +0000 (+0200) Subject: exp_ch4.adb (Expand_N_And_Then, [...]): Improve constant folding. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=deff3e5e46d740c9b857bf96daf9f9206bd22ea7;p=platform%2Fupstream%2Fgcc.git exp_ch4.adb (Expand_N_And_Then, [...]): Improve constant folding. 2008-08-20 Bob Duff * exp_ch4.adb (Expand_N_And_Then, Expand_N_Or_Else): Improve constant folding. We were folding things like "False and then ...", but not "X and then ..." where X is a constant whose value is known at compile time. From-SVN: r139304 --- diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 2f95a84..c0c2041 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -3591,34 +3591,33 @@ package body Exp_Ch4 is Set_Etype (N, Standard_Boolean); end if; - -- Check for cases of left argument is True or False + -- Check for cases where left argument is known to be True or False - if Nkind (Left) = N_Identifier then + if Compile_Time_Known_Value (Left) then -- If left argument is True, change (True and then Right) to Right. -- Any actions associated with Right will be executed unconditionally -- and can thus be inserted into the tree unconditionally. - if Entity (Left) = Standard_True then + if Expr_Value_E (Left) = Standard_True then if Present (Actions (N)) then Insert_Actions (N, Actions (N)); end if; Rewrite (N, Right); - Adjust_Result_Type (N, Typ); - return; -- If left argument is False, change (False and then Right) to False. -- In this case we can forget the actions associated with Right, -- since they will never be executed. - elsif Entity (Left) = Standard_False then + else pragma Assert (Expr_Value_E (Left) = Standard_False); Kill_Dead_Code (Right); Kill_Dead_Code (Actions (N)); Rewrite (N, New_Occurrence_Of (Standard_False, Loc)); - Adjust_Result_Type (N, Typ); - return; end if; + + Adjust_Result_Type (N, Typ); + return; end if; -- If Actions are present, we expand @@ -3650,19 +3649,19 @@ package body Exp_Ch4 is -- No actions present, check for cases of right argument True/False - if Nkind (Right) = N_Identifier then + if Compile_Time_Known_Value (Right) then -- Change (Left and then True) to Left. Note that we know there are -- no actions associated with the True operand, since we just checked -- for this case above. - if Entity (Right) = Standard_True then + if Expr_Value_E (Right) = Standard_True then Rewrite (N, Left); -- Change (Left and then False) to False, making sure to preserve any -- side effects associated with the Left operand. - elsif Entity (Right) = Standard_False then + else pragma Assert (Expr_Value_E (Right) = Standard_False); Remove_Side_Effects (Left); Rewrite (N, New_Occurrence_Of (Standard_False, Loc)); @@ -6707,34 +6706,33 @@ package body Exp_Ch4 is Set_Etype (N, Standard_Boolean); end if; - -- Check for cases of left argument is True or False + -- Check for cases where left argument is known to be True or False - if Nkind (Left) = N_Identifier then + if Compile_Time_Known_Value (Left) then -- If left argument is False, change (False or else Right) to Right. -- Any actions associated with Right will be executed unconditionally -- and can thus be inserted into the tree unconditionally. - if Entity (Left) = Standard_False then + if Expr_Value_E (Left) = Standard_False then if Present (Actions (N)) then Insert_Actions (N, Actions (N)); end if; Rewrite (N, Right); - Adjust_Result_Type (N, Typ); - return; -- If left argument is True, change (True and then Right) to True. In -- this case we can forget the actions associated with Right, since -- they will never be executed. - elsif Entity (Left) = Standard_True then + else pragma Assert (Expr_Value_E (Left) = Standard_True); Kill_Dead_Code (Right); Kill_Dead_Code (Actions (N)); Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); - Adjust_Result_Type (N, Typ); - return; end if; + + Adjust_Result_Type (N, Typ); + return; end if; -- If Actions are present, we expand @@ -6766,19 +6764,19 @@ package body Exp_Ch4 is -- No actions present, check for cases of right argument True/False - if Nkind (Right) = N_Identifier then + if Compile_Time_Known_Value (Right) then -- Change (Left or else False) to Left. Note that we know there are -- no actions associated with the True operand, since we just checked -- for this case above. - if Entity (Right) = Standard_False then + if Expr_Value_E (Right) = Standard_False then Rewrite (N, Left); -- Change (Left or else True) to True, making sure to preserve any -- side effects associated with the Left operand. - elsif Entity (Right) = Standard_True then + else pragma Assert (Expr_Value_E (Right) = Standard_True); Remove_Side_Effects (Left); Rewrite (N, New_Occurrence_Of (Standard_True, Loc));