summaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-strength-reduction.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gimple-ssa-strength-reduction.c')
-rw-r--r--gcc/gimple-ssa-strength-reduction.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c
index 8d48adde01d..88afc91200f 100644
--- a/gcc/gimple-ssa-strength-reduction.c
+++ b/gcc/gimple-ssa-strength-reduction.c
@@ -42,12 +42,17 @@ along with GCC; see the file COPYING3. If not see
#include "tree-pass.h"
#include "cfgloop.h"
#include "gimple-pretty-print.h"
-#include "tree-ssa.h"
+#include "gimple-ssa.h"
+#include "tree-cfg.h"
+#include "tree-phinodes.h"
+#include "ssa-iterators.h"
+#include "tree-ssanames.h"
#include "domwalk.h"
#include "pointer-set.h"
#include "expmed.h"
#include "params.h"
#include "hash-table.h"
+#include "tree-ssa-address.h"
/* Information about a strength reduction candidate. Each statement
in the candidate table represents an expression of one of the
@@ -379,6 +384,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 +774,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);
@@ -786,7 +800,7 @@ backtrace_base_for_ref (tree *pbase)
else if (base_cand->kind == CAND_ADD
&& TREE_CODE (base_cand->stride) == INTEGER_CST
&& integer_onep (base_cand->stride))
- {
+ {
/* X = B + (i * S), S is integer one. */
*pbase = base_cand->base_expr;
return base_cand->index;
@@ -3564,8 +3578,8 @@ const pass_data pass_data_strength_reduction =
class pass_strength_reduction : public gimple_opt_pass
{
public:
- pass_strength_reduction(gcc::context *ctxt)
- : gimple_opt_pass(pass_data_strength_reduction, ctxt)
+ pass_strength_reduction (gcc::context *ctxt)
+ : gimple_opt_pass (pass_data_strength_reduction, ctxt)
{}
/* opt_pass methods: */