On 15 Apr 14:07, Ilya Enkovich wrote: > 2015-04-14 8:22 GMT+03:00 Jeff Law <l...@redhat.com>: > > On 03/15/2015 02:30 PM, Richard Sandiford wrote: > >> > >> Ilya Enkovich <enkovich....@gmail.com> writes: > >>> > >>> This patch allows propagation of loop invariants for i386 if propagated > >>> value is a constant to be used in address operand. Bootstrapped and > >>> tested on x86_64-unknown-linux-gnu. OK for trunk or stage 1? > >> > >> > >> Is it necessary for this to be a target hook? The concept doesn't seem > >> particularly target-specific. We should only propagate into the address > >> if the new cost is no greater than the old cost, but if the address > >> meets that condition and if propagating at this point in the pipeline is > >> a win on x86, then wouldn't it be a win for other targets too? > > > > I agree with Richard here. I can't see a strong reason why this should be a > > target hook. > > > > Perhaps part of the issue here is the address costing metrics may not have > > enough context to make good decisions. In which case what context do they > > need? > > At this point I don't insist on a target hook. The main reasoning was > to not affect other targets. If we extend propagation for non constant > values different aspects may appear. E.g. possible register pressure > changes may significantly affect ia32. I just wanted to have an > instrument to play with a propagation on x86 not affecting other > targets. I don't have an opportunity to test possible performance > implications on non-x86 targets. Don't expect (significant) > regressions there but who knows... > > I'll remove the hook from this patch. Will probably introduce it later > if some target specific cases are found. > > Thanks, > Ilya > > > > > Jeff
Here is a version with no hook. Bootstrapped and tested on x86_64-unknown-linux-gnu. Is it OK for trunk? Thanks, Ilya -- gcc/ 2015-04-17 Ilya Enkovich <ilya.enkov...@intel.com> PR target/65103 * fwprop.c (forward_propagate_into): Propagate loop invariants if a target says so. gcc/testsuite/ 2015-04-17 Ilya Enkovich <ilya.enkov...@intel.com> PR target/65103 * gcc.target/i386/pr65103-2.c: New. diff --git a/gcc/fwprop.c b/gcc/fwprop.c index fc64ec9..82ebd01 100644 --- a/gcc/fwprop.c +++ b/gcc/fwprop.c @@ -1365,8 +1365,18 @@ forward_propagate_into (df_ref use) if (DF_REF_IS_ARTIFICIAL (def)) return false; - /* Do not propagate loop invariant definitions inside the loop. */ - if (DF_REF_BB (def)->loop_father != DF_REF_BB (use)->loop_father) + def_insn = DF_REF_INSN (def); + if (multiple_sets (def_insn)) + return false; + def_set = single_set (def_insn); + if (!def_set) + return false; + + /* Do not propagate loop invariant definitions inside the loop. + Allow address constant propagation. */ + if (DF_REF_BB (def)->loop_father != DF_REF_BB (use)->loop_father + && (DF_REF_TYPE (use) == DF_REF_REG_USE + || GET_CODE (SET_SRC (def_set)) != CONST)) return false; /* Check if the use is still present in the insn! */ @@ -1379,13 +1389,6 @@ forward_propagate_into (df_ref use) if (!reg_mentioned_p (DF_REF_REG (use), parent)) return false; - def_insn = DF_REF_INSN (def); - if (multiple_sets (def_insn)) - return false; - def_set = single_set (def_insn); - if (!def_set) - return false; - /* Only try one kind of propagation. If two are possible, we'll do it on the following iterations. */ if (forward_propagate_and_simplify (use, def_insn, def_set) diff --git a/gcc/testsuite/gcc.target/i386/pr65103-2.c b/gcc/testsuite/gcc.target/i386/pr65103-2.c new file mode 100644 index 0000000..b7a32f7 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr65103-2.c @@ -0,0 +1,24 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-require-effective-target pie } */ +/* { dg-options "-O2 -fPIE" } */ +/* { dg-final { scan-assembler-not "GOTOFF," } } */ + +typedef struct S +{ + int a; + int b; +} S; +struct S gs; + +extern int compute ( struct S * ); + +int test( void ) +{ + int t = -1; + while (t) + { + gs.a++; + t = compute (&gs); + } + return 0; +}