[PATCH] Fix PR34130, extract_muldiv broken

View: New views
3 Messages — Rating Filter:   Alert me  

[PATCH] Fix PR34130, extract_muldiv broken

by Richard Guenther-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


It folds -C*ABS<n> to ABS<-C*n>.  Anyone else thinks this function needs
to go? :/

Bootstrapped & tested on x86_64-unknown-linux-gnu, applied to mainline.

Richard.

2007-11-17  Richard Guenther  <rguenther@...>

        PR middle-end/34130
        * fold-const.c (extract_muldiv_1): Do not move negative
        constants inside ABS_EXPR.

        * gcc.c-torture/execute/pr34130.c: New testcase.

Index: fold-const.c
===================================================================
*** fold-const.c (revision 130238)
--- fold-const.c (working copy)
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 6095,6100 ****
--- 6095,6103 ----
              }
            break;
          }
+       /* If the constant is negative, we cannot simplify this.  */
+       if (tree_int_cst_sgn (c) == -1)
+         break;
        /* FALLTHROUGH */
      case NEGATE_EXPR:
        if ((t1 = extract_muldiv (op0, c, code, wide_type, strict_overflow_p))
Index: testsuite/gcc.c-torture/execute/pr34130.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr34130.c (revision 0)
--- testsuite/gcc.c-torture/execute/pr34130.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ extern void abort (void);
+ int foo (int i)
+ {
+   return -2 * __builtin_abs(i - 2);
+ }
+ int main()
+ {
+   if (foo(1) != -2
+       || foo(3) != -2)
+     abort ();
+   return 0;
+ }

Re: [PATCH] Fix PR34130, extract_muldiv broken

by Matthias Klose-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Richard Guenther writes:

>
> It folds -C*ABS<n> to ABS<-C*n>.  Anyone else thinks this function needs
> to go? :/
>
> Bootstrapped & tested on x86_64-unknown-linux-gnu, applied to mainline.
>
> Richard.
>
> 2007-11-17  Richard Guenther  <rguenther@...>
>
> PR middle-end/34130
> * fold-const.c (extract_muldiv_1): Do not move negative
> constants inside ABS_EXPR.
>
> * gcc.c-torture/execute/pr34130.c: New testcase.

The same patch applies to the 4.2 branch as well. checked on
sparc-linux-gnu without regressions. Ok to checkin?

Currently running the testsuite on the 4.1 branch. Ok to check in on
this branch, if the testsuite succeeds without regressions?

  Matthias

Re: [PATCH] Fix PR34130, extract_muldiv broken

by Richard Guenther-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 22, 2007 2:18 PM, Matthias Klose <doko@...> wrote:

> Richard Guenther writes:
> >
> > It folds -C*ABS<n> to ABS<-C*n>.  Anyone else thinks this function needs
> > to go? :/
> >
> > Bootstrapped & tested on x86_64-unknown-linux-gnu, applied to mainline.
> >
> > Richard.
> >
> > 2007-11-17  Richard Guenther  <rguenther@...>
> >
> >       PR middle-end/34130
> >       * fold-const.c (extract_muldiv_1): Do not move negative
> >       constants inside ABS_EXPR.
> >
> >       * gcc.c-torture/execute/pr34130.c: New testcase.
>
> The same patch applies to the 4.2 branch as well. checked on
> sparc-linux-gnu without regressions. Ok to checkin?
>
> Currently running the testsuite on the 4.1 branch. Ok to check in on
> this branch, if the testsuite succeeds without regressions?

Ok for both.

Thanks,
Richard.