This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Improve MIN_EXPR/MAX_EXPR constant folding
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Eric Botcazou <ebotcazou at adacore dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 14 Jan 2006 11:16:47 -0500
- Subject: Re: [PATCH] Improve MIN_EXPR/MAX_EXPR constant folding
- References: <200601141201.42807.ebotcazou@adacore.com>
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