OSDN Git Service

PR optimization/13318
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Dec 2003 12:57:13 +0000 (12:57 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Dec 2003 12:57:13 +0000 (12:57 +0000)
* loop.c (express_from): Protect integer division from overflow.

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

gcc/ChangeLog
gcc/loop.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/overflow-1.c [new file with mode: 0644]

index c37ec9b..ade64d8 100644 (file)
@@ -1,5 +1,10 @@
 2003-12-07  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
+       PR optimization/13318
+       * loop.c (express_from): Protect integer division from overflow.
+
+2003-12-07  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
        PR optimization/13060
        * function.c (fixup_var_refs_1) [SUBREG]: Recognize even if a
        replacement already exists.  Fix again the whole insn if that fails.
index 77567f8..373ff14 100644 (file)
@@ -7196,6 +7196,9 @@ express_from (struct induction *g1, struct induction *g2)
       && GET_CODE (g2->mult_val) == CONST_INT)
     {
       if (g1->mult_val == const0_rtx
+         || (g1->mult_val == constm1_rtx
+             && INTVAL (g2->mult_val)
+                == (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1))
          || INTVAL (g2->mult_val) % INTVAL (g1->mult_val) != 0)
        return NULL_RTX;
       mult = GEN_INT (INTVAL (g2->mult_val) / INTVAL (g1->mult_val));
index 3e1be98..b075f0e 100644 (file)
@@ -1,3 +1,7 @@
+2003-12-07  Wolfgang Bangerth  <bangerth@dealii.org>
+
+       * gcc.dg/overflow-1.c: New test.
+
 2003-12-07  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * g77.f-torture/compile/13060.f: New test.
diff --git a/gcc/testsuite/gcc.dg/overflow-1.c b/gcc/testsuite/gcc.dg/overflow-1.c
new file mode 100644 (file)
index 0000000..db51a5e
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR optimization/13318 */
+/* Origin: <bremner@unb.ca> */
+/* Reduced testcase: Wolfgang Bangerth <bangerth@dealii.org> */
+
+/* Verify that the big multiplier doesn't cause an integer
+   overflow in the loop optimizer.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct S {
+  int key;
+  int rnext,rprev;
+};
+void foo(struct S* H)
+{
+  int i, k;
+  for (i=0; i<2; i++){
+    struct S* cell=H+k;
+    cell->key=i*(0xffffffffUL/2);
+    cell->rnext=k+(1-i);
+    cell->rprev=k+(1-i);
+  }
+}