From: Richard Biener Date: Wed, 10 May 2017 07:53:45 +0000 (+0000) Subject: Backport PRs 80122, 80222, 80334, 80539 X-Git-Tag: releases/gcc-5.5.0~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc3a9eb7df5b5a07460461903764479e2d550d6c;p=thirdparty%2Fgcc.git Backport PRs 80122, 80222, 80334, 80539 2017-05-10 Richard Biener Backport from mainline 2017-03-21 Richard Biener PR tree-optimization/80122 * tree-inline.c (copy_bb): Do not expans va-arg packs or va_arg_pack_len when the inlined call stmt requires pack expansion itself. * tree-inline.h (struct copy_body_data): Make call_stmt a gcall *. * gcc.dg/torture/pr80122.c: New testcase. 2017-03-28 Richard Biener PR middle-end/80222 * gimple-fold.c (gimple_fold_indirect_ref): Do not touch TYPE_REF_CAN_ALIAS_ALL references. * fold-const.c (fold_indirect_ref_1): Likewise. * g++.dg/pr80222.C: New testcase. 2017-04-06 Richard Biener PR tree-optimization/80334 * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly preserve alignment of accesses. * g++.dg/torture/pr80334.C: New testcase. 2017-04-27 Richard Biener PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. From-SVN: r247827 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8058a1b4c6ef..9d509b935b1e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,34 @@ +2017-05-10 Richard Biener + + Backport from mainline + 2017-03-21 Richard Biener + + PR tree-optimization/80122 + * tree-inline.c (copy_bb): Do not expans va-arg packs or + va_arg_pack_len when the inlined call stmt requires pack + expansion itself. + * tree-inline.h (struct copy_body_data): Make call_stmt a gcall *. + + 2017-03-28 Richard Biener + + PR middle-end/80222 + * gimple-fold.c (gimple_fold_indirect_ref): Do not touch + TYPE_REF_CAN_ALIAS_ALL references. + * fold-const.c (fold_indirect_ref_1): Likewise. + + 2017-04-06 Richard Biener + + PR tree-optimization/80334 + * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly + preserve alignment of accesses. + + 2017-04-27 Richard Biener + + PR middle-end/80539 + * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not + being in loop-closed SSA form conservatively. + (chrec_fold_multiply_poly_poly): Likewise. + 2016-05-08 Bill Schmidt Backport from mainline diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7adefba83cbc..48b32532421d 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -15876,7 +15876,8 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0) STRIP_NOPS (sub); subtype = TREE_TYPE (sub); - if (!POINTER_TYPE_P (subtype)) + if (!POINTER_TYPE_P (subtype) + || TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (op0))) return NULL_TREE; if (TREE_CODE (sub) == ADDR_EXPR) diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 7950cb627fd0..81dc92064e24 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -5910,8 +5910,8 @@ gimple_val_nonnegative_real_p (tree val) return false; } -/* Given a pointer value OP0, return a simplified version of an - indirection through OP0, or NULL_TREE if no simplification is +/* Given a pointer value T, return a simplified version of an + indirection through T, or NULL_TREE if no simplification is possible. Note that the resulting type may be different from the type pointed to in the sense that it is still compatible from the langhooks point of view. */ @@ -5925,7 +5925,8 @@ gimple_fold_indirect_ref (tree t) STRIP_NOPS (sub); subtype = TREE_TYPE (sub); - if (!POINTER_TYPE_P (subtype)) + if (!POINTER_TYPE_P (subtype) + || TYPE_REF_CAN_ALIAS_ALL (ptype)) return NULL_TREE; if (TREE_CODE (sub) == ADDR_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0654ebc64114..d2b6972e1577 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,26 @@ +2017-05-10 Richard Biener + + Backport from mainline + 2017-03-21 Richard Biener + + PR tree-optimization/80122 + * gcc.dg/torture/pr80122.c: New testcase. + + 2017-03-28 Richard Biener + + PR middle-end/80222 + * g++.dg/pr80222.C: New testcase. + + 2017-04-06 Richard Biener + + PR tree-optimization/80334 + * g++.dg/torture/pr80334.C: New testcase. + + 2017-04-27 Richard Biener + + PR middle-end/80539 + * gcc.dg/torture/pr80539.c: New testcase. + 2016-05-08 Bill Schmidt Backport from mainline diff --git a/gcc/testsuite/g++.dg/pr80222.C b/gcc/testsuite/g++.dg/pr80222.C new file mode 100644 index 000000000000..ed1b37f5e374 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr80222.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-optimized" } */ + +struct C { int i; }__attribute__((may_alias)) ; + +C a, b; + +int main() +{ + a = static_cast (b); +} + +// { dg-final { scan-tree-dump "{ref-all}\\\)&b\];" "optimized" } } */ diff --git a/gcc/testsuite/g++.dg/torture/pr80334.C b/gcc/testsuite/g++.dg/torture/pr80334.C new file mode 100644 index 000000000000..ba990e733fa1 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr80334.C @@ -0,0 +1,19 @@ +// { dg-do run } +// { dg-additional-options "-std=c++11" } + +struct A { alignas(16) char c; }; +struct B { A unpacked; char d; } __attribute__((packed)); + +char x; + +int +main() +{ + alignas(__BIGGEST_ALIGNMENT__) B b[3]; + for (int i = 0; i < 3; i++) b[i].unpacked.c = 'a' + i; + for (int i = 0; i < 3; i++) + { + auto a = new A(b[i].unpacked); + x = a->c; + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr80122.c b/gcc/testsuite/gcc.dg/torture/pr80122.c new file mode 100644 index 000000000000..a76d756c32e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr80122.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ + +#define __GNU_ALWAYS_INLINE inline __attribute__(( __always_inline__)) + +#define DEVT_ALL 0 + +#define CMD_ABI_DEVICES 100 + +static __GNU_ALWAYS_INLINE int +send_msg_to_gm_w_dev_t(int msg_type, unsigned int dev_msg_type, + int devt, ...) +{ + char s[256]; + int nArgs = __builtin_va_arg_pack_len(); + if (nArgs != 2) + __builtin_abort (); + __builtin_sprintf (s, "%d", __builtin_va_arg_pack ()); + if (__builtin_strcmp (s, "99") != 0) + __builtin_abort (); + /* do something with nArgs and ... */ + return 0; +} + +static __GNU_ALWAYS_INLINE int +send_msg_to_gm(int msg_type, unsigned int dev_msg_type, + ...) +{ + int nArgs = __builtin_va_arg_pack_len(); + if (nArgs != 2) + __builtin_abort (); + return send_msg_to_gm_w_dev_t(msg_type, dev_msg_type, + DEVT_ALL, __builtin_va_arg_pack()); +} + +static __GNU_ALWAYS_INLINE int +send_enable(unsigned int dev_msg_type, ...) +{ + int nArgs = __builtin_va_arg_pack_len(); + if (nArgs != 2) + __builtin_abort (); + return send_msg_to_gm(CMD_ABI_DEVICES, dev_msg_type, __builtin_va_arg_pack()); +} + +int +main(void) +{ + int mode = 99; + + send_enable(1, mode, sizeof(mode)); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr80539.c b/gcc/testsuite/gcc.dg/torture/pr80539.c new file mode 100644 index 000000000000..a66767814d3f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr80539.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ + +signed char a, b; +void fn1() +{ + signed char c, e; + short d; + if (0) { + for (; d;) { +l1: + for (c = 7; a; c++) + ; + e = 6; + for (; b; e++) + ; + } + c -= e; + } + if (d == 7) + goto l1; + a = c; +} diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index b4a8d821c565..bbc05fbf9971 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -167,7 +167,12 @@ chrec_fold_plus_poly_poly (enum tree_code code, /* This function should never be called for chrecs of loops that do not belong to the same loop nest. */ - gcc_assert (loop0 == loop1); + if (loop0 != loop1) + { + /* It still can happen if we are not in loop-closed SSA form. */ + gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA)); + return chrec_dont_know; + } if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR) { @@ -229,7 +234,12 @@ chrec_fold_multiply_poly_poly (tree type, chrec_fold_multiply (type, CHREC_LEFT (poly0), poly1), CHREC_RIGHT (poly0)); - gcc_assert (loop0 == loop1); + if (loop0 != loop1) + { + /* It still can happen if we are not in loop-closed SSA form. */ + gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA)); + return chrec_dont_know; + } /* poly0 and poly1 are two polynomials in the same variable, {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */ diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 83fb5d3eb39a..71d9d239535a 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1852,7 +1852,8 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale, call_stmt = dyn_cast (stmt); if (call_stmt && gimple_call_va_arg_pack_p (call_stmt) - && id->call_stmt) + && id->call_stmt + && ! gimple_call_va_arg_pack_p (id->call_stmt)) { /* __builtin_va_arg_pack () should be replaced by all arguments corresponding to ... in the caller. */ @@ -1932,7 +1933,8 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale, && id->call_stmt && (decl = gimple_call_fndecl (stmt)) && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL - && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN) + && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN + && ! gimple_call_va_arg_pack_p (id->call_stmt)) { /* __builtin_va_arg_pack_len () should be replaced by the number of anonymous arguments. */ @@ -4580,7 +4582,7 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id) id->src_fn = fn; id->src_node = cg_edge->callee; id->src_cfun = DECL_STRUCT_FUNCTION (fn); - id->call_stmt = stmt; + id->call_stmt = call_stmt; gcc_assert (!id->src_cfun->after_inlining); diff --git a/gcc/tree-inline.h b/gcc/tree-inline.h index f8b2ebfe2dde..b3f616cdeb7a 100644 --- a/gcc/tree-inline.h +++ b/gcc/tree-inline.h @@ -101,7 +101,7 @@ struct copy_body_data /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL is not. */ - gimple call_stmt; + gcall *call_stmt; /* Exception landing pad the inlined call lies in. */ int eh_lp_nr; diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 1d642610cb78..0ef0ad55f164 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -6628,7 +6628,11 @@ rewrite_use_address (struct ivopts_data *data, base_hint = var_at_stmt (data->current_loop, cand, use->stmt); iv = var_at_stmt (data->current_loop, cand, use->stmt); - ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff, + tree type = TREE_TYPE (*use->op_p); + unsigned int align = get_object_alignment (*use->op_p); + if (align != TYPE_ALIGN (type)) + type = build_aligned_type (type, align); + ref = create_mem_ref (&bsi, type, &aff, reference_alias_ptr_type (*use->op_p), iv, base_hint, data->speed); copy_ref_info (ref, *use->op_p);