aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYufeng Zhang <yufeng@gcc.gnu.org>2013-10-02 10:21:33 +0000
committerYufeng Zhang <yufeng@gcc.gnu.org>2013-10-02 10:21:33 +0000
commit0916f876074b952b3003300a273baa14e6dab8af (patch)
tree7cbf4cbc19fbaec019e8762b73c36e2e7d3de655
parentebfcd719cf1ca5c186befb9ea013add7342b1cb2 (diff)
downloadgcc-0916f876074b952b3003300a273baa14e6dab8af.zip
gcc-0916f876074b952b3003300a273baa14e6dab8af.tar.gz
gcc-0916f876074b952b3003300a273baa14e6dab8af.tar.bz2
gimple-ssa-strength-reduction.c (legal_cast_p_1): Forward declaration.
gcc/ * gimple-ssa-strength-reduction.c (legal_cast_p_1): Forward declaration. (backtrace_base_for_ref): Call get_unwidened with 'base_in' if 'base_in' represent a conversion and legal_cast_p_1 holds; set 'base_in' with the returned value from get_unwidened. gcc/testsuite/ * gcc.dg/tree-ssa/slsr-40.c: New test. From-SVN: r203107
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/gimple-ssa-strength-reduction.c9
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/slsr-40.c27
4 files changed, 49 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7dc504b..76d188f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2013-10-02 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
+ Yufeng Zhang <yufeng.zhang@arm.com>
+
+ * gimple-ssa-strength-reduction.c (legal_cast_p_1): Forward
+ declaration.
+ (backtrace_base_for_ref): Call get_unwidened with 'base_in' if
+ 'base_in' represent a conversion and legal_cast_p_1 holds; set
+ 'base_in' with the returned value from get_unwidened.
+
2013-10-02 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* config/arm/arm.c (arm_legitimize_reload_address): Explain why
diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c
index 139a4a1..9a5072c 100644
--- a/gcc/gimple-ssa-strength-reduction.c
+++ b/gcc/gimple-ssa-strength-reduction.c
@@ -379,6 +379,7 @@ static bool address_arithmetic_p;
/* Forward function declarations. */
static slsr_cand_t base_cand_from_table (tree);
static tree introduce_cast_before_cand (slsr_cand_t, tree, tree);
+static bool legal_cast_p_1 (tree, tree);
/* Produce a pointer to the IDX'th candidate in the candidate vector. */
@@ -768,6 +769,14 @@ backtrace_base_for_ref (tree *pbase)
slsr_cand_t base_cand;
STRIP_NOPS (base_in);
+
+ /* Strip off widening conversion(s) to handle cases where
+ e.g. 'B' is widened from an 'int' in order to calculate
+ a 64-bit address. */
+ if (CONVERT_EXPR_P (base_in)
+ && legal_cast_p_1 (base_in, TREE_OPERAND (base_in, 0)))
+ base_in = get_unwidened (base_in, NULL_TREE);
+
if (TREE_CODE (base_in) != SSA_NAME)
return tree_to_double_int (integer_zero_node);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cb2f58c..2fb3cc6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2013-10-02 Yufeng Zhang <yufeng.zhang@arm.com>
+
+ * gcc.dg/tree-ssa/slsr-40.c: New test.
+
2013-10-01 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58563
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/slsr-40.c b/gcc/testsuite/gcc.dg/tree-ssa/slsr-40.c
new file mode 100644
index 0000000..72726a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/slsr-40.c
@@ -0,0 +1,27 @@
+/* Verify straight-line strength reduction for array
+ subscripting.
+
+ elems[n-1] is reduced to elems + n * 4 + 0xffffffff * 4, only when
+ pointers are of the same size as that of int (assuming 4 bytes). */
+
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+struct data
+{
+ unsigned long elms[1];
+} gData;
+
+void __attribute__((noinline))
+foo (struct data *dst, unsigned int n)
+{
+ dst->elms[n - 1] &= 1;
+}
+
+int
+main ()
+{
+ foo (&gData, 1);
+ return 0;
+}
+