This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Improve MIN_EXPR/MAX_EXPR constant folding



On Jan 14, 2006, at 6:01 AM, Eric Botcazou wrote:


Hi,

The attached Ada testcase triggers an ICE in the gimplifier

eric@linux:~/build/gcc/native> gcc/xgcc -Bgcc -S bug_list.adb
+===========================GNAT BUG DETECTED==============================+
| 4.2.0 20060108 (experimental) (x86_64-suse-linux-gnu) GCC error: |
| in create_tmp_var, at gimplify.c:410 |
| Error detected at bug_list.adb:9:8


because the compiler is trying to create a temporary with a variable-sized
type. It turns out that the type actually has a fixed size, but the
expression of the size is of the form:


The calculation's type is signed (long int sizetype) so the compiler cannot
constant-fold the tree to 4. The proposed fix is to teach fold how to
simplify MIN (MAX (arg, val), val) and its sibling expression.


Bootstrapped/regtested on x86_64-linux-gnu. OK for mainline?

I would add some C testcases. Like: /* { dg-do compile } */ /* { dg-options "-O1 -fdump-tree-optimized" } */

int f(int a, int c)
{
  return (a > c?a:c)>c?c:(a > c?a:c);
}

/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "optimized"} } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
----------------------------------------
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */

int f(int a, int c)
{
  return c<(a < c?a:c)?(a < c?a:c):c;
}

/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "optimized"} } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */

This should simplify now as we get in fold "MIN_EXPR <MAX_EXPR <c, a>, c>;" and
"MAX_EXPR <MIN_EXPR <c, a>, c>". Oh, I see you are comparing only constants, I think
that is wrong as shown by my example.


-- Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]