diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-20 14:27:50 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-20 14:27:50 +0000 |
commit | 694fbb34026012ea7ee1669ac86719a4910cc4e1 (patch) | |
tree | c08133b942bdfbbdc34891f607732e710e1a692f /gcc | |
parent | 7b1d52add9af84292a151979f2d8aa927f1c0c7b (diff) | |
download | ppe42-gcc-694fbb34026012ea7ee1669ac86719a4910cc4e1.tar.gz ppe42-gcc-694fbb34026012ea7ee1669ac86719a4910cc4e1.zip |
2008-08-20 Bob Duff <duff@adacore.com>
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@139304 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_ch4.adb | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 2f95a84207d..c0c20416276 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)); |