aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2010-11-03 17:33:31 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2010-11-03 17:33:31 +0000
commitfdb8b4c025aaec6ef208c0af698cc3faa87d15dd (patch)
treec41ccdf4f2a83d3a7481104e5f49d0bedf5f94fc
parent5554928d3d05201ad1b0c826c5221ead783f765f (diff)
downloadgcc-fdb8b4c025aaec6ef208c0af698cc3faa87d15dd.zip
gcc-fdb8b4c025aaec6ef208c0af698cc3faa87d15dd.tar.gz
gcc-fdb8b4c025aaec6ef208c0af698cc3faa87d15dd.tar.bz2
tree-tailcall.c (find_tail_calls): Convert the operands to the type of the result before building binary expressions.
* tree-tailcall.c (find_tail_calls): Convert the operands to the type of the result before building binary expressions. From-SVN: r166260
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/opt8.adb48
-rw-r--r--gcc/testsuite/gnat.dg/opt8.ads46
-rw-r--r--gcc/testsuite/gnat.dg/opt8_pkg.ads7
-rw-r--r--gcc/tree-tailcall.c8
6 files changed, 116 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d57d461..1e16506 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-03 Eric Botcazou <ebotcazou@adacore.com>
+
+ * tree-tailcall.c (find_tail_calls): Convert the operands to the type
+ of the result before building binary expressions.
+
2010-11-03 H.J. Lu <hongjiu.lu@intel.com>
PR rtl-optimization/45865
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 207119b..26555d7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-03 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gnat.dg/opt8.ad[sb]: New test.
+ * gnat.dg/opt8_pkg.ads: New helper.
+
2010-11-03 H.J. Lu <hongjiu.lu@intel.com>
PR rtl-optimization/45865
diff --git a/gcc/testsuite/gnat.dg/opt8.adb b/gcc/testsuite/gnat.dg/opt8.adb
new file mode 100644
index 0000000..72145fd
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt8.adb
@@ -0,0 +1,48 @@
+-- { dg-do compile }
+-- { dg-options "-O2" }
+
+with Opt8_Pkg;
+
+package body Opt8 is
+
+ function Content_Value (Rec : Kappa_Component_Rec)
+ return Value_Number is
+ begin
+ return Opt8_Pkg.Id_To_VN (Rec.Content_VN);
+ end;
+
+ function Possible_Values_Count (V: Kappa_Component_Ptr) return Natural is
+ Result : Natural := 0;
+ List : Kappa_Component_Ptr := V;
+ begin
+ while List /= null loop
+ Result := Result +1;
+ List := List.Next;
+ end loop;
+ return Result;
+ end;
+
+ function VN_Complexity (Val : Value_Number; N : Natural)
+ return Natural is
+ Result : Natural := 0;
+ begin
+ case Val.Kind is
+ when Membership_VN =>
+ Result := VN_Complexity(Val, N);
+ when Selected_Address_VN =>
+ Result := VN_Complexity(Val, N) + 1;
+ when Kappa_VN =>
+ Result := Possible_Values_Count(Val.Possible_New_Values)*3;
+ if Val.Use_Default then
+ if Result < N then
+ Result := Result +
+ VN_Complexity(Content_Value (Val.old_Value), N);
+ end if;
+ end if;
+ when others =>
+ Result := 0;
+ end case;
+ return Result;
+ end;
+
+end Opt8;
diff --git a/gcc/testsuite/gnat.dg/opt8.ads b/gcc/testsuite/gnat.dg/opt8.ads
new file mode 100644
index 0000000..57d84a2
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt8.ads
@@ -0,0 +1,46 @@
+package Opt8 is
+
+ type Value_Number_Kind is
+ (Int_Literal_VN,
+ Selected_Address_VN,
+ Membership_VN,
+ Initial_External_Kappa_VN,
+ Aliased_Kappa_VN,
+ Phi_As_Kappa_VN,
+ Multi_Target_Call_Kappa_VN,
+ Final_Value_Of_Seq_Kappa_VN,
+ Block_Kappa_VN);
+
+ subtype Kappa_VN is Value_Number_Kind
+ range Initial_External_Kappa_VN .. Block_Kappa_VN;
+
+ type Value_Number_Id is new Positive;
+
+ type Kappa_Component_Rec;
+
+ type Kappa_Component_Ptr is access Kappa_Component_Rec;
+
+ type Kappa_Component_Rec is record
+ Content_VN : Value_Number_Id;
+ Next : Kappa_Component_Ptr;
+ end record;
+
+ type Value_Number_Rec(Kind : Value_Number_Kind) is record
+ Id: Value_Number_Id;
+ case Kind is
+ when Int_Literal_VN =>
+ Int_Val : Integer;
+ when Kappa_VN =>
+ Old_Value : Kappa_Component_Rec;
+ Possible_New_Values : Kappa_Component_Ptr;
+ Use_Default : Boolean;
+ when Others =>
+ null;
+ end case;
+ end record;
+
+ type Value_Number is access all Value_Number_Rec;
+
+ function VN_Complexity (Val : Value_Number; N : Natural) return Natural;
+
+end Opt8;
diff --git a/gcc/testsuite/gnat.dg/opt8_pkg.ads b/gcc/testsuite/gnat.dg/opt8_pkg.ads
new file mode 100644
index 0000000..3e39f11
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt8_pkg.ads
@@ -0,0 +1,7 @@
+with Opt8; use Opt8;
+
+package Opt8_Pkg is
+
+ function Id_To_VN (Id: Value_Number_Id) return Value_Number;
+
+end Opt8_Pkg;
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index 38daed9..10ae450 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -532,20 +532,22 @@ find_tail_calls (basic_block bb, struct tailcall **ret)
if (tmp_a)
{
+ tree type = TREE_TYPE (tmp_a);
if (a)
- a = fold_build2 (PLUS_EXPR, TREE_TYPE (tmp_a), a, tmp_a);
+ a = fold_build2 (PLUS_EXPR, type, fold_convert (type, a), tmp_a);
else
a = tmp_a;
}
if (tmp_m)
{
+ tree type = TREE_TYPE (tmp_m);
if (m)
- m = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), m, tmp_m);
+ m = fold_build2 (MULT_EXPR, type, fold_convert (type, m), tmp_m);
else
m = tmp_m;
if (a)
- a = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), a, tmp_m);
+ a = fold_build2 (MULT_EXPR, type, fold_convert (type, a), tmp_m);
}
}