From: Marek Polacek Date: Thu, 9 Jul 2015 09:01:51 +0000 (+0000) Subject: re PR tree-optimization/66718 (Non-invariant ADDR_EXPR not vectorized) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca87c493f78fc19c4196e28cfe137add40bf2932;p=gcc.git re PR tree-optimization/66718 (Non-invariant ADDR_EXPR not vectorized) PR tree-optimization/66718 * Makefile.in (OBJS): Add gimple-laddress.o. * passes.def: Schedule pass_laddress. * timevar.def (DEFTIMEVAR): Add TV_GIMPLE_LADDRESS. * tree-pass.h (make_pass_laddress): Declare. * gimple-laddress.c: New file. * gcc.dg/vect/vect-126.c: New test. From-SVN: r225604 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2af5e00021f..a0d835e1efd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-07-09 Marek Polacek + + PR tree-optimization/66718 + * Makefile.in (OBJS): Add gimple-laddress.o. + * passes.def: Schedule pass_laddress. + * timevar.def (DEFTIMEVAR): Add TV_GIMPLE_LADDRESS. + * tree-pass.h (make_pass_laddress): Declare. + * gimple-laddress.c: New file. + 2015-07-09 Richard Biener * toplev.c (compile_file): Reset maximum_field_alignment after parsing. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 89eda968d52..181702517cc 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1255,6 +1255,7 @@ OBJS = \ gimple-expr.o \ gimple-iterator.o \ gimple-fold.o \ + gimple-laddress.o \ gimple-low.o \ gimple-match.o \ generic-match.o \ diff --git a/gcc/gimple-laddress.c b/gcc/gimple-laddress.c new file mode 100644 index 00000000000..c8036b90d1e --- /dev/null +++ b/gcc/gimple-laddress.c @@ -0,0 +1,137 @@ +/* Lower and optimize address expressions. + Copyright (C) 2015 Free Software Foundation, Inc. + Contributed by Marek Polacek + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "alias.h" +#include "predict.h" +#include "tm.h" +#include "function.h" +#include "dominance.h" +#include "cfg.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "symtab.h" +#include "tree.h" +#include "stringpool.h" +#include "tree-ssanames.h" +#include "fold-const.h" +#include "gimple-expr.h" +#include "gimple.h" +#include "gimplify.h" +#include "gimple-iterator.h" +#include "gimplify-me.h" +#include "tree-pass.h" + + +namespace { + +const pass_data pass_data_laddress = +{ + GIMPLE_PASS, /* type */ + "laddress", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_GIMPLE_LADDRESS, /* tv_id */ + ( PROP_cfg | PROP_ssa ), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_laddress : public gimple_opt_pass +{ +public: + pass_laddress (gcc::context *ctxt) + : gimple_opt_pass (pass_data_laddress, ctxt) + {} + + /* opt_pass methods: */ + opt_pass * clone () { return new pass_laddress (m_ctxt); } + virtual bool gate (function *) { return optimize != 0; } + virtual unsigned int execute (function *); + +}; // class pass_laddress + +unsigned int +pass_laddress::execute (function *fun) +{ + basic_block bb; + + FOR_EACH_BB_FN (bb, fun) + { + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) + { + gimple stmt = gsi_stmt (gsi); + if (!is_gimple_assign (stmt) + || gimple_assign_rhs_code (stmt) != ADDR_EXPR + || is_gimple_invariant_address (gimple_assign_rhs1 (stmt))) + { + gsi_next (&gsi); + continue; + } + + /* Lower ADDR_EXPR assignments: + _4 = &b[i_9]; + into + _1 = (sizetype) i_9; + _7 = _1 * 4; + _4 = &b + _7; + This ought to aid the vectorizer and expose CSE opportunities. + */ + + tree expr = gimple_assign_rhs1 (stmt); + HOST_WIDE_INT bitsize, bitpos; + tree base, offset; + machine_mode mode; + int volatilep = 0, unsignedp = 0; + base = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize, + &bitpos, &offset, &mode, &unsignedp, + &volatilep, false); + gcc_assert (base != NULL_TREE && (bitpos % BITS_PER_UNIT) == 0); + if (offset != NULL_TREE) + { + if (bitpos != 0) + offset = size_binop (PLUS_EXPR, offset, + size_int (bitpos / BITS_PER_UNIT)); + offset = force_gimple_operand_gsi (&gsi, offset, true, NULL, + true, GSI_SAME_STMT); + base = build_fold_addr_expr (base); + base = force_gimple_operand_gsi (&gsi, base, true, NULL, + true, GSI_SAME_STMT); + gimple g = gimple_build_assign (gimple_assign_lhs (stmt), + POINTER_PLUS_EXPR, base, offset); + gsi_replace (&gsi, g, false); + } + gsi_next (&gsi); + } + } + + return 0; +} + +} // anon namespace + +gimple_opt_pass * +make_pass_laddress (gcc::context *ctxt) +{ + return new pass_laddress (ctxt); +} diff --git a/gcc/passes.def b/gcc/passes.def index 0d8356b9bda..5cd07aed8f4 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -213,6 +213,7 @@ along with GCC; see the file COPYING3. If not see form if possible. */ NEXT_PASS (pass_cse_sincos); NEXT_PASS (pass_optimize_bswap); + NEXT_PASS (pass_laddress); NEXT_PASS (pass_split_crit_edges); NEXT_PASS (pass_pre); NEXT_PASS (pass_sink_code); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 092f4c7ff10..661ccb52de1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-07-09 Marek Polacek + + PR tree-optimization/66718 + * gcc.dg/vect/vect-126.c: New test. + 2015-07-08 Carlos Sánchez de La Lama * g++.dg/debug/dwarf2/*.C: generate dwarf-2 debug information diff --git a/gcc/testsuite/gcc.dg/vect/vect-126.c b/gcc/testsuite/gcc.dg/vect/vect-126.c new file mode 100644 index 00000000000..f01b95e1920 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-126.c @@ -0,0 +1,63 @@ +/* PR tree-optimization/66718 */ +/* { dg-do compile } */ + +int *a[1024], b[1024]; +struct S { int u, v, w, x; }; +struct S c[1024]; +int d[1024][10]; + +void +f0 (void) +{ + for (int i = 0; i < 1024; i++) + a[i] = &b[0]; +} + +void +f1 (void) +{ + for (int i = 0; i < 1024; i++) + { + int *p = &b[0]; + a[i] = p + i; + } +} + +void +f2 (int *p) +{ + for (int i = 0; i < 1024; i++) + a[i] = &p[i]; +} + +void +f3 (void) +{ + for (int i = 0; i < 1024; i++) + a[i] = &b[i]; +} + +void +f4 (void) +{ + int *p = &c[0].v; + for (int i = 0; i < 1024; i++) + a[i] = &p[4 * i]; +} + +void +f5 (void) +{ + for (int i = 0; i < 1024; i++) + a[i] = &c[i].v; +} + +void +f6 (void) +{ + for (int i = 0; i < 1024; i++) + for (unsigned int j = 0; j < 10; j++) + a[i] = &d[i][j]; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 7 "vect" { target { i?86-*-* x86_64-*-* } } } } */ diff --git a/gcc/timevar.def b/gcc/timevar.def index efac4b791ad..aee36e6941d 100644 --- a/gcc/timevar.def +++ b/gcc/timevar.def @@ -275,6 +275,7 @@ DEFTIMEVAR (TV_GIMPLE_SLSR , "straight-line strength reduction") DEFTIMEVAR (TV_VTABLE_VERIFICATION , "vtable verification") DEFTIMEVAR (TV_TREE_UBSAN , "tree ubsan") DEFTIMEVAR (TV_INITIALIZE_RTL , "initialize rtl") +DEFTIMEVAR (TV_GIMPLE_LADDRESS , "address lowering") /* Everything else in rest_of_compilation not included above. */ DEFTIMEVAR (TV_EARLY_LOCAL , "early local passes") diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 2808dad2d7d..c47b22eb2ee 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -393,6 +393,7 @@ extern gimple_opt_pass *make_pass_cd_dce (gcc::context *ctxt); extern gimple_opt_pass *make_pass_call_cdce (gcc::context *ctxt); extern gimple_opt_pass *make_pass_merge_phi (gcc::context *ctxt); extern gimple_opt_pass *make_pass_split_crit_edges (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_laddress (gcc::context *ctxt); extern gimple_opt_pass *make_pass_pre (gcc::context *ctxt); extern unsigned int tail_merge_optimize (unsigned int); extern gimple_opt_pass *make_pass_profile (gcc::context *ctxt);