aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2016-09-01 15:56:13 +0000
committerEric Botcazou <ebotcazou@adacore.com>2016-09-01 15:56:13 +0000
commitee68eee1316a997019fa2fe1f9a5ccdc9f9dbce0 (patch)
treead1c9b7f642244178757ab66921230a45896508c
parente8227485a77b4c730167764bb6b1860b34af2625 (diff)
* ipa-inline-analysis.c (param_change_prob): Get to the base object
first in all cases. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@239943 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/ipa-inline-analysis.c22
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/opt58.adb19
-rw-r--r--gcc/testsuite/gnat.dg/opt58_pkg.ads19
5 files changed, 60 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7d80216bc0e..223cf33121f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-09-01 Eric Botcazou <ebotcazou@adacore.com>
+
+ * ipa-inline-analysis.c (param_change_prob): Get to the base object
+ first in all cases.
+
2016-09-01 Segher Boessenkool <segher@kernel.crashing.org>
* config/rs6000/rs6000.md (*restore_gpregs_<mode>_r11,
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index c8b1fefc288..132779d2621 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -2183,28 +2183,33 @@ param_change_prob (gimple *stmt, int i)
{
tree op = gimple_call_arg (stmt, i);
basic_block bb = gimple_bb (stmt);
- tree base;
- /* Global invariants neve change. */
- if (is_gimple_min_invariant (op))
+ if (TREE_CODE (op) == WITH_SIZE_EXPR)
+ op = TREE_OPERAND (op, 0);
+
+ tree base = get_base_address (op);
+
+ /* Global invariants never change. */
+ if (is_gimple_min_invariant (base))
return 0;
+
/* We would have to do non-trivial analysis to really work out what
is the probability of value to change (i.e. when init statement
is in a sibling loop of the call).
We do an conservative estimate: when call is executed N times more often
than the statement defining value, we take the frequency 1/N. */
- if (TREE_CODE (op) == SSA_NAME)
+ if (TREE_CODE (base) == SSA_NAME)
{
int init_freq;
if (!bb->frequency)
return REG_BR_PROB_BASE;
- if (SSA_NAME_IS_DEFAULT_DEF (op))
+ if (SSA_NAME_IS_DEFAULT_DEF (base))
init_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;
else
- init_freq = gimple_bb (SSA_NAME_DEF_STMT (op))->frequency;
+ init_freq = gimple_bb (SSA_NAME_DEF_STMT (base))->frequency;
if (!init_freq)
init_freq = 1;
@@ -2213,9 +2218,7 @@ param_change_prob (gimple *stmt, int i)
else
return REG_BR_PROB_BASE;
}
-
- base = get_base_address (op);
- if (base)
+ else
{
ao_ref refd;
int max;
@@ -2256,7 +2259,6 @@ param_change_prob (gimple *stmt, int i)
else
return REG_BR_PROB_BASE;
}
- return REG_BR_PROB_BASE;
}
/* Find whether a basic block BB is the final block of a (half) diamond CFG
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 721307738e4..3f6ff1dcef4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-09-01 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gnat.dg/opt58.adb: New test.
+ * gnat.dg/opt58_pkg.ads: New helper.
+
2016-09-01 Richard Biener <rguenther@suse.de>
PR middle-end/77436
diff --git a/gcc/testsuite/gnat.dg/opt58.adb b/gcc/testsuite/gnat.dg/opt58.adb
new file mode 100644
index 00000000000..ac39cc06056
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt58.adb
@@ -0,0 +1,19 @@
+-- { dg-do compile }
+-- { dg-options "-O" }
+
+with Unchecked_Conversion;
+with System; use System;
+with Opt58_Pkg; use Opt58_Pkg;
+
+procedure Opt58 is
+
+ function Convert is new Unchecked_Conversion (Integer, Rec);
+
+ Dword : Integer := 0;
+ I : Small_Int := F1 (Convert (Dword));
+
+begin
+ if F2 (Null_Address, I = 0) then
+ null;
+ end if;
+end Opt58;
diff --git a/gcc/testsuite/gnat.dg/opt58_pkg.ads b/gcc/testsuite/gnat.dg/opt58_pkg.ads
new file mode 100644
index 00000000000..9cb7f3a2540
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt58_pkg.ads
@@ -0,0 +1,19 @@
+with System; use System;
+
+package Opt58_Pkg is
+
+ pragma Pure (Opt58_Pkg);
+
+ type Small_Int is range 0 .. 255;
+
+ type Rec is record
+ D1, D2, D3, D4 : Small_Int;
+ end record;
+ pragma Pack (Rec);
+ for Rec'Size use 32;
+
+ function F1 (R : Rec) return Small_Int;
+
+ function F2 (A : Address; B : Boolean) return Boolean;
+
+end Opt58_Pkg;