simplify-rtx.c (simplify_plus_minus): Bump n_ops for NOT.
authorJakub Jelinek <jakub@redhat.com>
Mon, 7 Jan 2002 21:13:25 +0000 (22:13 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 7 Jan 2002 21:13:25 +0000 (22:13 +0100)
* simplify-rtx.c (simplify_plus_minus): Bump n_ops for NOT.
Don't allow -1 - x -> ~x simplifications in the first pass.

* gcc.c-torture/execute/20020107-1.c: New test.

From-SVN: r48614

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20020107-1.c [new file with mode: 0644]

index 7aa7478..bac2003 100644 (file)
@@ -1,3 +1,8 @@
+2002-01-07  Jakub Jelinek  <jakub@redhat.com>
+
+       * simplify-rtx.c (simplify_plus_minus): Bump n_ops for NOT.
+       Don't allow -1 - x -> ~x simplifications in the first pass.
+
 2002-01-07  Aldy Hernandez  <aldyh@redhat.com>
 
         * rs6000.c (altivec_expand_ternop_builtin): Don't die on invalid
index 84209cc..84a9ce9 100644 (file)
@@ -1800,7 +1800,7 @@ simplify_plus_minus (code, mode, op0, op1)
              if (n_ops != 7)
                {
                  ops[n_ops].op = constm1_rtx;
-                 ops[n_ops].neg = this_neg;
+                 ops[n_ops++].neg = this_neg;
                  ops[i].op = XEXP (this_op, 0);
                  ops[i].neg = !this_neg;
                  changed = 1;
@@ -1865,7 +1865,13 @@ simplify_plus_minus (code, mode, op0, op1)
                    && ! (GET_CODE (tem) == CONST
                          && GET_CODE (XEXP (tem, 0)) == ncode
                          && XEXP (XEXP (tem, 0), 0) == lhs
-                         && XEXP (XEXP (tem, 0), 1) == rhs))
+                         && XEXP (XEXP (tem, 0), 1) == rhs)
+                   /* Don't allow -x + -1 -> ~x simplifications in the
+                      first pass.  This allows us the chance to combine
+                      the -1 with other constants.  */
+                   && ! (first
+                         && GET_CODE (tem) == NOT
+                         && XEXP (tem, 0) == rhs))
                  {
                    lneg &= rneg;
                    if (GET_CODE (tem) == NEG)
index 6a5b170..d6de456 100644 (file)
@@ -1,3 +1,7 @@
+2002-01-07  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.c-torture/execute/20020107-1.c: New test.
+
 2002-01-06  Craig Rodrigues  <rodrigc@gcc.gnu.org>
 
        PR c/5279
diff --git a/gcc/testsuite/gcc.c-torture/execute/20020107-1.c b/gcc/testsuite/gcc.c-torture/execute/20020107-1.c
new file mode 100644 (file)
index 0000000..d5bbcc4
--- /dev/null
@@ -0,0 +1,28 @@
+/* This testcase failed because - 1 - buf was simplified into ~buf and when
+   later expanding it back into - buf + -1, -1 got lost.  */
+
+extern void abort (void);
+extern void exit (int);
+
+static void
+bar (int x)
+{
+  if (!x)
+    abort ();
+}
+
+char buf[10];
+
+inline char *
+foo (char *tmp)
+{
+  asm ("" : "=r" (tmp) : "0" (tmp));
+  return tmp + 2;
+}
+
+int
+main (void)
+{
+  bar ((foo (buf) - 1 - buf) == 1);
+  exit (0);
+}