From 0ec41e9fbb443ea0f5e340c8fe63ffd8752e8fd1 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 14 Feb 2017 11:45:31 +0100 Subject: [PATCH] backport: [multiple changes] 2016-03-01 Richard Biener 2017-02-14 Martin Liska Backport from mainline 2016-03-01 Richard Biener PR middle-end/70022 PR target/79498 * fold-const.c (fold_indirect_ref_1): Fix range checking for vector BIT_FIELD_REF extract. From-SVN: r245426 --- gcc/ChangeLog | 10 ++++++++++ gcc/fold-const.c | 23 +++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1f02d717b6be..c7452e1b3cc7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2017-02-14 Martin Liska + + Backport from mainline + 2016-03-01 Richard Biener + + PR middle-end/70022 + PR target/79498 + * fold-const.c (fold_indirect_ref_1): Fix range checking for + vector BIT_FIELD_REF extract. + 2017-02-14 Martin Liska Backport from mainline diff --git a/gcc/fold-const.c b/gcc/fold-const.c index fa58a5a6aab6..7adefba83cbc 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -15942,17 +15942,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 -- 2.47.2