From: Eric Botcazou Date: Thu, 1 Sep 2016 15:56:13 +0000 (+0000) Subject: ipa-inline-analysis.c (param_change_prob): Get to the base object first in all cases. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0a6b05234a625802bb1f75ee66e61b404da20434;p=gcc.git ipa-inline-analysis.c (param_change_prob): Get to the base object first in all cases. * ipa-inline-analysis.c (param_change_prob): Get to the base object first in all cases. From-SVN: r239943 --- 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 + + * ipa-inline-analysis.c (param_change_prob): Get to the base object + first in all cases. + 2016-09-01 Segher Boessenkool * config/rs6000/rs6000.md (*restore_gpregs__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 + + * gnat.dg/opt58.adb: New test. + * gnat.dg/opt58_pkg.ads: New helper. + 2016-09-01 Richard Biener 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;