gcc/
authoryufeng <yufeng@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Oct 2013 10:21:33 +0000 (10:21 +0000)
committeryufeng <yufeng@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Oct 2013 10:21:33 +0000 (10:21 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@203107 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimple-ssa-strength-reduction.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/slsr-40.c [new file with mode: 0644]

index 7dc504b..76d188f 100644 (file)
@@ -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
index 139a4a1..9a5072c 100644 (file)
@@ -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);
 \f
 /* 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);
 
index cb2f58c..2fb3cc6 100644 (file)
@@ -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 (file)
index 0000000..72726a3
--- /dev/null
@@ -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;
+}
+