summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-18 15:13:14 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-18 15:13:14 +0000
commitc133c5a226403740682bfa073465fe6b5413391e (patch)
tree07f42e9a1f87a588fb04291412d2299d9d822b26
parentf56e71e96a808adc43db88f297dd48eeea3b9358 (diff)
downloadgcc-c133c5a226403740682bfa073465fe6b5413391e.tar.gz
2013-11-18 Richard Biener <rguenther@suse.de>
Backport from mainline 2013-10-21 Richard Biener <rguenther@suse.de> PR tree-optimization/58794 * fold-const.c (operand_equal_p): Compare FIELD_DECL operand of COMPONENT_REFs with OEP_CONSTANT_ADDRESS_OF left in place. * c-c++-common/torture/pr58794-1.c: New testcase. * c-c++-common/torture/pr58794-2.c: Likewise. 2013-10-21 Richard Biener <rguenther@suse.de> PR middle-end/58742 * fold-const.c (fold_binary_loc): Fold ((T) (X /[ex] C)) * C to (T) X for sign-changing conversions (or no conversion). * c-c++-common/fold-divmul-1.c: New testcase. 2013-11-06 Richard Biener <rguenther@suse.de> PR tree-optimization/58653 * tree-predcom.c (ref_at_iteration): Rewrite to generate a MEM_REF. (prepare_initializers_chain): Adjust. * gcc.dg/tree-ssa/predcom-6.c: New testcase. * gcc.dg/tree-ssa/predcom-7.c: Likewise. PR tree-optimization/59047 * tree-predcom.c (ref_at_iteration): Handle bitfield accesses properly. * gcc.dg/torture/pr59047.c: New testcase. 2013-10-15 Richard Biener <rguenther@suse.de> PR tree-optimization/58143 * tree-ssa-loop-im.c (arith_code_with_undefined_signed_overflow): New function. (rewrite_to_defined_overflow): Likewise. (move_computations_dom_walker::before_dom): Rewrite stmts with undefined signed overflow that are not always executed into unsigned arithmetic. * gcc.dg/torture/pr58143-1.c: New testcase. * gcc.dg/torture/pr58143-2.c: Likewise. * gcc.dg/torture/pr58143-3.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_8-branch@204965 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog36
-rw-r--r--gcc/fold-const.c12
-rw-r--r--gcc/testsuite/ChangeLog30
-rw-r--r--gcc/testsuite/c-c++-common/fold-divmul-1.c11
-rw-r--r--gcc/testsuite/c-c++-common/torture/pr58794-1.c29
-rw-r--r--gcc/testsuite/c-c++-common/torture/pr58794-2.c21
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr58143-1.c51
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr58143-2.c34
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr58143-3.c18
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr59047.c39
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/predcom-6.c14
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c18
-rw-r--r--gcc/tree-predcom.c123
-rw-r--r--gcc/tree-ssa-loop-im.c77
14 files changed, 423 insertions, 90 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e580b142333..d4ea6919fea 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,39 @@
+2013-11-18 Richard Biener <rguenther@suse.de>
+
+ Backport from mainline
+ 2013-10-21 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58794
+ * fold-const.c (operand_equal_p): Compare FIELD_DECL operand
+ of COMPONENT_REFs with OEP_CONSTANT_ADDRESS_OF left in place.
+
+ 2013-10-21 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/58742
+ * fold-const.c (fold_binary_loc): Fold ((T) (X /[ex] C)) * C
+ to (T) X for sign-changing conversions (or no conversion).
+
+ 2013-11-06 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58653
+ * tree-predcom.c (ref_at_iteration): Rewrite to generate
+ a MEM_REF.
+ (prepare_initializers_chain): Adjust.
+
+ PR tree-optimization/59047
+ * tree-predcom.c (ref_at_iteration): Handle bitfield accesses
+ properly.
+
+ 2013-10-15 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58143
+ * tree-ssa-loop-im.c (arith_code_with_undefined_signed_overflow):
+ New function.
+ (rewrite_to_defined_overflow): Likewise.
+ (move_computations_dom_walker::before_dom): Rewrite stmts
+ with undefined signed overflow that are not always executed
+ into unsigned arithmetic.
+
2013-11-14 Uros Bizjak <ubizjak@gmail.com>
Backport from mainline
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6dc8934f33b..f66642980bb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2664,10 +2664,11 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
case COMPONENT_REF:
/* Handle operand 2 the same as for ARRAY_REF. Operand 0
may be NULL when we're called to compare MEM_EXPRs. */
- if (!OP_SAME_WITH_NULL (0))
+ if (!OP_SAME_WITH_NULL (0)
+ || !OP_SAME (1))
return 0;
flags &= ~OEP_CONSTANT_ADDRESS_OF;
- return OP_SAME (1) && OP_SAME_WITH_NULL (2);
+ return OP_SAME_WITH_NULL (2);
case BIT_FIELD_REF:
if (!OP_SAME (0))
@@ -10927,6 +10928,13 @@ fold_binary_loc (location_t loc,
fold_build2_loc (loc, MULT_EXPR, type,
build_int_cst (type, 2) , arg1));
+ /* ((T) (X /[ex] C)) * C cancels out if the conversion is
+ sign-changing only. */
+ if (TREE_CODE (arg1) == INTEGER_CST
+ && TREE_CODE (arg0) == EXACT_DIV_EXPR
+ && operand_equal_p (arg1, TREE_OPERAND (arg0, 1), 0))
+ return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f1a29349b0f..017b96f69d8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,33 @@
+2013-11-18 Richard Biener <rguenther@suse.de>
+
+ Backport from mainline
+ 2013-10-21 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58794
+ * c-c++-common/torture/pr58794-1.c: New testcase.
+ * c-c++-common/torture/pr58794-2.c: Likewise.
+
+ 2013-10-21 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/58742
+ * c-c++-common/fold-divmul-1.c: New testcase.
+
+ 2013-11-06 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58653
+ * gcc.dg/tree-ssa/predcom-6.c: New testcase.
+ * gcc.dg/tree-ssa/predcom-7.c: Likewise.
+
+ PR tree-optimization/59047
+ * gcc.dg/torture/pr59047.c: New testcase.
+
+ 2013-10-15 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/58143
+ * gcc.dg/torture/pr58143-1.c: New testcase.
+ * gcc.dg/torture/pr58143-2.c: Likewise.
+ * gcc.dg/torture/pr58143-3.c: Likewise.
+
2013-11-17 Janus Weil <janus@gcc.gnu.org>
Backport from mainline
diff --git a/gcc/testsuite/c-c++-common/fold-divmul-1.c b/gcc/testsuite/c-c++-common/fold-divmul-1.c
new file mode 100644
index 00000000000..5c867923d2e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fold-divmul-1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-original" } */
+
+int *
+fx (int *b, int *e)
+{
+ return b + (e - b);
+}
+
+/* { dg-final { scan-tree-dump-not "/\\\[ex\\\]" "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/pr58794-1.c b/gcc/testsuite/c-c++-common/torture/pr58794-1.c
new file mode 100644
index 00000000000..175629fec90
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr58794-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+
+struct S0
+{
+ int f;
+};
+
+struct S1
+{
+ struct S0 f1;
+ volatile int f2;
+};
+
+struct S2
+{
+ struct S1 g;
+} a, b;
+
+static int *c[1][2] = {{0, (int *)&a.g.f2}};
+static int d;
+
+int
+main ()
+{
+ for (d = 0; d < 1; d++)
+ for (b.g.f1.f = 0; b.g.f1.f < 1; b.g.f1.f++)
+ *c[b.g.f1.f][d + 1] = 0;
+ return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/torture/pr58794-2.c b/gcc/testsuite/c-c++-common/torture/pr58794-2.c
new file mode 100644
index 00000000000..767798806db
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr58794-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+struct S
+{
+ volatile int f;
+} a;
+
+unsigned int b;
+
+static int *c[1][2] = {{0, (int *)&a.f}};
+static unsigned int d;
+
+int
+main ()
+{
+ for (; d < 1; d++)
+ for (; b < 1; b++)
+ *c[b][d + 1] = 0;
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr58143-1.c b/gcc/testsuite/gcc.dg/torture/pr58143-1.c
new file mode 100644
index 00000000000..855515edb97
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr58143-1.c
@@ -0,0 +1,51 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fstrict-overflow" } */
+
+extern void abort (void);
+
+int a, b, c, d, e, f, g, h = 1, i;
+
+int foo (int p)
+{
+ return p < 0 && a < - __INT_MAX__ - 1 - p ? 0 : 1;
+}
+
+int *bar ()
+{
+ int j;
+ i = h ? 0 : 1 % h;
+ for (j = 0; j < 1; j++)
+ for (d = 0; d; d++)
+ for (e = 1; e;)
+ return 0;
+ return 0;
+}
+
+int baz ()
+{
+ for (; b >= 0; b--)
+ for (c = 1; c >= 0; c--)
+ {
+ int *k = &c;
+ for (;;)
+ {
+ for (f = 0; f < 1; f++)
+ {
+ g = foo (*k);
+ bar ();
+ }
+ if (*k)
+ break;
+ return 0;
+ }
+ }
+ return 0;
+}
+
+int main ()
+{
+ baz ();
+ if (b != 0)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr58143-2.c b/gcc/testsuite/gcc.dg/torture/pr58143-2.c
new file mode 100644
index 00000000000..dd0dae1efe0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr58143-2.c
@@ -0,0 +1,34 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fstrict-overflow" } */
+
+int a, b, d, e, f, *g, h, i;
+volatile int c;
+
+char foo (unsigned char p)
+{
+ return p + 1;
+}
+
+int bar ()
+{
+ for (h = 0; h < 3; h = foo (h))
+ {
+ c;
+ for (f = 0; f < 1; f++)
+ {
+ i = a && 0 < -__INT_MAX__ - h ? 0 : 1;
+ if (e)
+ for (; d;)
+ b = 0;
+ else
+ g = 0;
+ }
+ }
+ return 0;
+}
+
+int main ()
+{
+ bar ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr58143-3.c b/gcc/testsuite/gcc.dg/torture/pr58143-3.c
new file mode 100644
index 00000000000..23ae9cd39ce
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr58143-3.c
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fstrict-overflow" } */
+
+int a, b, c, d, e;
+
+int
+main ()
+{
+ for (b = 4; b > -30; b--)
+ for (; c;)
+ for (;;)
+ {
+ e = a > __INT_MAX__ - b;
+ if (d)
+ break;
+ }
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr59047.c b/gcc/testsuite/gcc.dg/torture/pr59047.c
new file mode 100644
index 00000000000..fcedfcba870
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr59047.c
@@ -0,0 +1,39 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+struct
+{
+ int f0;
+ int f1:1;
+ int f2:2;
+} a = {0, 0, 1};
+
+int b, c, *d, e, f;
+
+int
+fn1 ()
+{
+ for (; b < 1; ++b)
+ {
+ for (e = 0; e < 1; e = 1)
+ {
+ int **g = &d;
+ *g = &c;
+ }
+ *d = 0;
+ f = a.f1;
+ if (f)
+ return 0;
+ }
+ return 0;
+}
+
+int
+main ()
+{
+ fn1 ();
+ if (b != 1)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-6.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-6.c
new file mode 100644
index 00000000000..0af24381485
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-6.c
@@ -0,0 +1,14 @@
+/* { dg-do run } */
+/* { dg-options "-O3" } */
+
+int a, c, e[5][2];
+unsigned int d;
+
+int
+main ()
+{
+ for (d = 0; d < 2; d++)
+ if (a ? 0 : e[c + 3][d] & e[c + 4][d])
+ break;
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c
new file mode 100644
index 00000000000..e7ae87ccc7a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-options "-O3 -fdump-tree-pcom-details" } */
+
+int b, f, d[5][2];
+unsigned int c;
+
+int
+main ()
+{
+ for (c = 0; c < 2; c++)
+ if (d[b + 3][c] & d[b + 4][c])
+ if (f)
+ break;
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump "Executing predictive commoning" "pcom" } } */
+/* { dg-final { cleanup-tree-dump "pcom" } } */
diff --git a/gcc/tree-predcom.c b/gcc/tree-predcom.c
index dceea8cc89a..7bad2a29d1f 100644
--- a/gcc/tree-predcom.c
+++ b/gcc/tree-predcom.c
@@ -1323,90 +1323,43 @@ replace_ref_with (gimple stmt, tree new_tree, bool set, bool in_lhs)
gsi_insert_after (&bsi, new_stmt, GSI_NEW_STMT);
}
-/* Returns the reference to the address of REF in the ITER-th iteration of
- LOOP, or NULL if we fail to determine it (ITER may be negative). We
- try to preserve the original shape of the reference (not rewrite it
- as an indirect ref to the address), to make tree_could_trap_p in
- prepare_initializers_chain return false more often. */
-
-static tree
-ref_at_iteration (struct loop *loop, tree ref, int iter)
-{
- tree idx, *idx_p, type, val, op0 = NULL_TREE, ret;
- affine_iv iv;
- bool ok;
-
- if (handled_component_p (ref))
- {
- op0 = ref_at_iteration (loop, TREE_OPERAND (ref, 0), iter);
- if (!op0)
- return NULL_TREE;
- }
- else if (!INDIRECT_REF_P (ref)
- && TREE_CODE (ref) != MEM_REF)
- return unshare_expr (ref);
-
- if (TREE_CODE (ref) == MEM_REF)
- {
- ret = unshare_expr (ref);
- idx = TREE_OPERAND (ref, 0);
- idx_p = &TREE_OPERAND (ret, 0);
- }
- else if (TREE_CODE (ref) == COMPONENT_REF)
- {
- /* Check that the offset is loop invariant. */
- if (TREE_OPERAND (ref, 2)
- && !expr_invariant_in_loop_p (loop, TREE_OPERAND (ref, 2)))
- return NULL_TREE;
-
- return build3 (COMPONENT_REF, TREE_TYPE (ref), op0,
- unshare_expr (TREE_OPERAND (ref, 1)),
- unshare_expr (TREE_OPERAND (ref, 2)));
- }
- else if (TREE_CODE (ref) == ARRAY_REF)
- {
- /* Check that the lower bound and the step are loop invariant. */
- if (TREE_OPERAND (ref, 2)
- && !expr_invariant_in_loop_p (loop, TREE_OPERAND (ref, 2)))
- return NULL_TREE;
- if (TREE_OPERAND (ref, 3)
- && !expr_invariant_in_loop_p (loop, TREE_OPERAND (ref, 3)))
- return NULL_TREE;
-
- ret = build4 (ARRAY_REF, TREE_TYPE (ref), op0, NULL_TREE,
- unshare_expr (TREE_OPERAND (ref, 2)),
- unshare_expr (TREE_OPERAND (ref, 3)));
- idx = TREE_OPERAND (ref, 1);
- idx_p = &TREE_OPERAND (ret, 1);
- }
- else
- return NULL_TREE;
-
- ok = simple_iv (loop, loop, idx, &iv, true);
- if (!ok)
- return NULL_TREE;
- iv.base = expand_simple_operations (iv.base);
- if (integer_zerop (iv.step))
- *idx_p = unshare_expr (iv.base);
+/* Returns a memory reference to DR in the ITER-th iteration of
+ the loop it was analyzed in. Append init stmts to STMTS. */
+
+static tree
+ref_at_iteration (data_reference_p dr, int iter, gimple_seq *stmts)
+{
+ tree off = DR_OFFSET (dr);
+ tree coff = DR_INIT (dr);
+ if (iter == 0)
+ ;
+ else if (TREE_CODE (DR_STEP (dr)) == INTEGER_CST)
+ coff = size_binop (PLUS_EXPR, coff,
+ size_binop (MULT_EXPR, DR_STEP (dr), ssize_int (iter)));
else
- {
- type = TREE_TYPE (iv.base);
- if (POINTER_TYPE_P (type))
- {
- val = fold_build2 (MULT_EXPR, sizetype, iv.step,
- size_int (iter));
- val = fold_build_pointer_plus (iv.base, val);
- }
- else
- {
- val = fold_build2 (MULT_EXPR, type, iv.step,
- build_int_cst_type (type, iter));
- val = fold_build2 (PLUS_EXPR, type, iv.base, val);
- }
- *idx_p = unshare_expr (val);
+ off = size_binop (PLUS_EXPR, off,
+ size_binop (MULT_EXPR, DR_STEP (dr), ssize_int (iter)));
+ tree addr = fold_build_pointer_plus (DR_BASE_ADDRESS (dr), off);
+ addr = force_gimple_operand_1 (addr, stmts, is_gimple_mem_ref_addr,
+ NULL_TREE);
+ tree alias_ptr = fold_convert (reference_alias_ptr_type (DR_REF (dr)), coff);
+ /* While data-ref analysis punts on bit offsets it still handles
+ bitfield accesses at byte boundaries. Cope with that. Note that
+ we cannot simply re-apply the outer COMPONENT_REF because the
+ byte-granular portion of it is already applied via DR_INIT and
+ DR_OFFSET, so simply build a BIT_FIELD_REF knowing that the bits
+ start at offset zero. */
+ if (TREE_CODE (DR_REF (dr)) == COMPONENT_REF
+ && DECL_BIT_FIELD (TREE_OPERAND (DR_REF (dr), 1)))
+ {
+ tree field = TREE_OPERAND (DR_REF (dr), 1);
+ return build3 (BIT_FIELD_REF, TREE_TYPE (DR_REF (dr)),
+ build2 (MEM_REF, DECL_BIT_FIELD_TYPE (field),
+ addr, alias_ptr),
+ DECL_SIZE (field), bitsize_zero_node);
}
-
- return ret;
+ else
+ return fold_build2 (MEM_REF, TREE_TYPE (DR_REF (dr)), addr, alias_ptr);
}
/* Get the initialization expression for the INDEX-th temporary variable
@@ -2365,14 +2318,10 @@ prepare_initializers_chain (struct loop *loop, chain_p chain)
if (chain->inits[i] != NULL_TREE)
continue;
- init = ref_at_iteration (loop, DR_REF (dr), (int) i - n);
- if (!init)
- return false;
-
+ init = ref_at_iteration (dr, (int) i - n, &stmts);
if (!chain->all_always_accessed && tree_could_trap_p (init))
return false;
- init = force_gimple_operand (init, &stmts, false, NULL_TREE);
if (stmts)
gsi_insert_seq_on_edge_immediate (entry, stmts);
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 78ad0733016..72ed570dc55 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -1190,6 +1190,67 @@ determine_invariantness (void)
fini_walk_dominator_tree (&walk_data);
}
+/* Return true if CODE is an operation that when operating on signed
+ integer types involves undefined behavior on overflow and the
+ operation can be expressed with unsigned arithmetic. */
+
+static bool
+arith_code_with_undefined_signed_overflow (tree_code code)
+{
+ switch (code)
+ {
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ case MULT_EXPR:
+ case NEGATE_EXPR:
+ case POINTER_PLUS_EXPR:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* Rewrite STMT, an assignment with a signed integer or pointer arithmetic
+ operation that can be transformed to unsigned arithmetic by converting
+ its operand, carrying out the operation in the corresponding unsigned
+ type and converting the result back to the original type.
+
+ Returns a sequence of statements that replace STMT and also contain
+ a modified form of STMT itself. */
+
+static gimple_seq
+rewrite_to_defined_overflow (gimple stmt)
+{
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "rewriting stmt with undefined signed "
+ "overflow ");
+ print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
+ }
+
+ tree lhs = gimple_assign_lhs (stmt);
+ tree type = unsigned_type_for (TREE_TYPE (lhs));
+ gimple_seq stmts = NULL;
+ for (unsigned i = 1; i < gimple_num_ops (stmt); ++i)
+ {
+ gimple_seq stmts2 = NULL;
+ gimple_set_op (stmt, i,
+ force_gimple_operand (fold_convert (type,
+ gimple_op (stmt, i)),
+ &stmts2, true, NULL_TREE));
+ gimple_seq_add_seq (&stmts, stmts2);
+ }
+ gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt));
+ if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR)
+ gimple_assign_set_rhs_code (stmt, PLUS_EXPR);
+ gimple_seq_add_stmt (&stmts, stmt);
+ gimple cvt = gimple_build_assign_with_ops
+ (NOP_EXPR, lhs, gimple_assign_lhs (stmt), NULL_TREE);
+ gimple_seq_add_stmt (&stmts, cvt);
+
+ return stmts;
+}
+
/* Hoist the statements in basic block BB out of the loops prescribed by
data stored in LIM_DATA structures associated with each statement. Callback
for walk_dominator_tree. */
@@ -1321,7 +1382,21 @@ move_computations_stmt (struct dom_walk_data *dw_data,
}
}
gsi_remove (&bsi, false);
- gsi_insert_on_edge (e, stmt);
+ /* In case this is a stmt that is not unconditionally executed
+ when the target loop header is executed and the stmt may
+ invoke undefined integer or pointer overflow rewrite it to
+ unsigned arithmetic. */
+ if (is_gimple_assign (stmt)
+ && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt)))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (gimple_assign_lhs (stmt)))
+ && arith_code_with_undefined_signed_overflow
+ (gimple_assign_rhs_code (stmt))
+ && (!ALWAYS_EXECUTED_IN (bb)
+ || !(ALWAYS_EXECUTED_IN (bb) == level
+ || flow_loop_nested_p (ALWAYS_EXECUTED_IN (bb), level))))
+ gsi_insert_seq_on_edge (e, rewrite_to_defined_overflow (stmt));
+ else
+ gsi_insert_on_edge (e, stmt);
}
}