From: Richard Biener Date: Thu, 7 Jul 2016 11:46:08 +0000 (+0000) Subject: Backport PRs 70022, 70484, 70931, 71452 X-Git-Tag: releases/gcc-4.9.4~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c390d32d68079ad924e5b13d11fee7877a600585;p=thirdparty%2Fgcc.git Backport PRs 70022, 70484, 70931, 71452 2016-07-07 Richard Biener Backport from mainline 2016-04-04 Richard Biener PR rtl-optimization/70484 * rtl.h (canon_output_dependence): Declare. * alias.c (canon_output_dependence): New function. * dse.c (record_store): Use canon_output_dependence rather than canon_true_dependence. * gcc.dg/torture/pr70484.c: New testcase. 2016-06-08 Richard Biener PR tree-optimization/71452 * tree-ssa.c (non_rewritable_lvalue_p): Make sure that the type used for the SSA rewrite has enough precision to cover the dynamic type of the location. * gcc.dg/torture/pr71452.c: New testcase. 2016-05-06 Richard Biener PR middle-end/70931 * dwarf2out.c (native_encode_initializer): Skip zero-sized fields. * gfortran.dg/pr70931.f90: New testcase. 2016-03-01 Richard Biener PR middle-end/70022 * fold-const.c (fold_indirect_ref_1): Fix range checking for vector BIT_FIELD_REF extract. * gcc.dg/pr70022.c: New testcase. From-SVN: r238087 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 725d5aac29fc..78a009c3a458 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,32 @@ +2016-07-07 Richard Biener + + Backport from mainline + 2016-04-04 Richard Biener + + PR rtl-optimization/70484 + * rtl.h (canon_output_dependence): Declare. + * alias.c (canon_output_dependence): New function. + * dse.c (record_store): Use canon_output_dependence rather + than canon_true_dependence. + + 2016-06-08 Richard Biener + + PR tree-optimization/71452 + * tree-ssa.c (non_rewritable_lvalue_p): Make sure that the + type used for the SSA rewrite has enough precision to cover + the dynamic type of the location. + + 2016-05-06 Richard Biener + + PR middle-end/70931 + * dwarf2out.c (native_encode_initializer): Skip zero-sized fields. + + 2016-03-01 Richard Biener + + PR middle-end/70022 + * fold-const.c (fold_indirect_ref_1): Fix range checking for + vector BIT_FIELD_REF extract. + 2016-06-30 Jakub Jelinek PR middle-end/71693 diff --git a/gcc/alias.c b/gcc/alias.c index a1e554058d77..2711b7df5b46 100644 --- a/gcc/alias.c +++ b/gcc/alias.c @@ -2746,6 +2746,20 @@ output_dependence (const_rtx mem, const_rtx x) /*mem_canonicalized=*/false, /*x_canonicalized*/false, /*writep=*/true); } + +/* Likewise, but we already have a canonicalized MEM, and X_ADDR for X. + Also, consider X in X_MODE (which might be from an enclosing + STRICT_LOW_PART / ZERO_EXTRACT). + If MEM_CANONICALIZED is true, MEM is canonicalized. */ + +int +canon_output_dependence (const_rtx mem, bool mem_canonicalized, + const_rtx x, machine_mode x_mode, rtx x_addr) +{ + return write_dependence_p (mem, x, x_mode, x_addr, + mem_canonicalized, /*x_canonicalized=*/true, + /*writep=*/true); +} diff --git a/gcc/dse.c b/gcc/dse.c index 8ebf63f046e0..9392f6bccc1b 100644 --- a/gcc/dse.c +++ b/gcc/dse.c @@ -1639,10 +1639,9 @@ record_store (rtx body, bb_info_t bb_info) the value of store_info. If it is, set the rhs to NULL to keep it from being used to remove a load. */ { - if (canon_true_dependence (s_info->mem, - GET_MODE (s_info->mem), - s_info->mem_addr, - mem, mem_addr)) + if (canon_output_dependence (s_info->mem, true, + mem, GET_MODE (mem), + mem_addr)) { s_info->rhs = NULL; s_info->const_rhs = NULL; diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6b4e83ad5660..f3226b62b46b 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -15817,7 +15817,7 @@ native_encode_initializer (tree init, unsigned char *array, int size) fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field)); pos = int_byte_position (field); gcc_assert (pos + fieldsize <= size); - if (val + if (val && fieldsize != 0 && !native_encode_initializer (val, array + pos, fieldsize)) return false; } diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0f284020d49d..61bbf82e169c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -16742,17 +16742,20 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0) if (TREE_CODE (op00type) == VECTOR_TYPE && type == TREE_TYPE (op00type)) { - HOST_WIDE_INT offset = tree_to_shwi (op01); tree part_width = TYPE_SIZE (type); - unsigned HOST_WIDE_INT part_widthi = tree_to_shwi (part_width)/BITS_PER_UNIT; - unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; - tree index = bitsize_int (indexi); - - if (offset / part_widthi < TYPE_VECTOR_SUBPARTS (op00type)) - return fold_build3_loc (loc, - BIT_FIELD_REF, type, op00, - part_width, index); - + unsigned HOST_WIDE_INT max_offset + = (tree_to_uhwi (part_width) / BITS_PER_UNIT + * TYPE_VECTOR_SUBPARTS (op00type)); + if (tree_int_cst_sign_bit (op01) == 0 + && compare_tree_int (op01, max_offset) == -1) + { + unsigned HOST_WIDE_INT offset = tree_to_uhwi (op01); + unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; + tree index = bitsize_int (indexi); + return fold_build3_loc (loc, + BIT_FIELD_REF, type, op00, + part_width, index); + } } /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */ else if (TREE_CODE (op00type) == COMPLEX_TYPE diff --git a/gcc/rtl.h b/gcc/rtl.h index f1cda4c04b59..722ec796b3e0 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -2712,6 +2712,8 @@ extern int anti_dependence (const_rtx, const_rtx); extern int canon_anti_dependence (const_rtx, bool, const_rtx, enum machine_mode, rtx); extern int output_dependence (const_rtx, const_rtx); +extern int canon_output_dependence (const_rtx, bool, + const_rtx, machine_mode, rtx); extern int may_alias_p (const_rtx, const_rtx); extern void init_alias_target (void); extern void init_alias_analysis (void); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9564581837da..650afb05ed11 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,26 @@ +2016-07-07 Richard Biener + + Backport from mainline + 2016-04-04 Richard Biener + + PR rtl-optimization/70484 + * gcc.dg/torture/pr70484.c: New testcase. + + 2016-06-08 Richard Biener + + PR tree-optimization/71452 + * gcc.dg/torture/pr71452.c: New testcase. + + 2016-05-06 Richard Biener + + PR middle-end/70931 + * gfortran.dg/pr70931.f90: New testcase. + + 2016-03-01 Richard Biener + + PR middle-end/70022 + * gcc.dg/pr70022.c: New testcase. + 2016-06-30 Jakub Jelinek PR middle-end/71693 diff --git a/gcc/testsuite/g++.dg/torture/pr71452.C b/gcc/testsuite/g++.dg/torture/pr71452.C new file mode 100644 index 000000000000..3ebe3a176f36 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr71452.C @@ -0,0 +1,10 @@ +// { dg-do run } + +int main() +{ + bool b; + *(char *)&b = 123; + if (*(char *)&b != 123) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr70022.c b/gcc/testsuite/gcc.dg/pr70022.c new file mode 100644 index 000000000000..c7e60b8f1534 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70022.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ + +typedef int v4si __attribute__ ((vector_size (16))); + +int +foo (v4si v) +{ + return v[~0UL]; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr70484.c b/gcc/testsuite/gcc.dg/torture/pr70484.c new file mode 100644 index 000000000000..7604c654fbe5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr70484.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ + +extern void abort (void); + +int __attribute__((noinline,noclone)) +f(int *pi, long *pl) +{ + *pi = 1; + *pl = 0; + return *(char *)pi; +} + +int main() +{ + union { long l; int i; } a; + if (f (&a.i, &a.l) != 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr71452.c b/gcc/testsuite/gcc.dg/torture/pr71452.c new file mode 100644 index 000000000000..8948d39fdafd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr71452.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ + +int main() +{ + _Bool b; + *(char *)&b = 123; + if (*(char *)&b != 123) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gfortran.dg/pr70931.f90 b/gcc/testsuite/gfortran.dg/pr70931.f90 new file mode 100644 index 000000000000..08ecd6877526 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr70931.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { dg-options "-g" } +program p + type t + integer :: a + integer :: b(0) + end type + type(t), parameter :: z = t(1, [2]) + print *, z +end diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 8ea1853fa892..3d3ffaa89820 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1380,6 +1380,14 @@ non_rewritable_lvalue_p (tree lhs) tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0); if (DECL_P (decl) && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs)) + /* If the dynamic type of the decl has larger precision than + the decl itself we can't use the decls type for SSA rewriting. */ + && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl)) + || compare_tree_int (DECL_SIZE (decl), + TYPE_PRECISION (TREE_TYPE (decl))) == 0) + || (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && (TYPE_PRECISION (TREE_TYPE (decl)) + >= TYPE_PRECISION (TREE_TYPE (lhs))))) && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs))) return false; }