This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug optimization/14682] [tree-ssa] error: Invalid operand to binary operator
- From: law at redhat dot com
- To: gcc-bugzilla at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: law at gcc dot gnu dot org
- Date: Thu, 01 Apr 2004 10:32:08 -0700
- Subject: Re: [Bug optimization/14682] [tree-ssa] error: Invalid operand to binary operator
- Reply-to: law at redhat dot com
In message <20040322221127.1513.qmail@sources.redhat.com>, "pinskia at gcc dot
gnu dot org" writes:
>
>------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-22 2
>2:11 -------
>Here is a version which uses char instead of long/long long's:
>int __atomic_readv_replacement(unsigned char iov_len, int count, int i) {
> unsigned char bytes = 0;
> if ((unsigned char)((char)127 - bytes) < iov_len)
> return 22;
> return 0;
>}
>
>The problem is that fold is converting 127 < iov_len into (char)( iov_len) <
> 0 which is right but it is not gimple.
Correct. This is the fault of fold_relational_hi_lo (and it's one of the
reasons why I suggested to Kazu that he not try and merge it back to the
mainline). I've got a hack which disables this behavior when we're in gimple
form (Richard -- any progress on rewriting the folder around the design we
discussed a couple weeks ago?)
Additionally, I noticed that fold_stmt in tree-ssa-ccp.c was not checking
return values as closely as it should. I fixed that too.
Finally, while working on improving the way we handle updating the SSA
graph after jump threading I noticed two places where we could stop walking
down the list of PHI nodes when we really should have kept going. I haven't
been able to trigger a real failure due to this bug, but it clearly needs
to be fixed.
Bootstrapped and regression tested on i686-pc-linux-gnu. I'll check in the
simplified testcase fir 14682 shortly.
* fold-const.c (fold_relational_hi_lo): Do not return non-gimple
code when we are in gimple form.
* tree-optimize.c (tree_rest_of_compilation): Note when we are in
gimple form.
* tree-ssa-ccp.c (ccp_fold): Tighten tests on return value from
nondestructive_fold_{unary,binary}to_constant.
* tree.h (in_gimple_form): Declare.
* tree-ssa.c (ssa_remove_edge): Correct looping structure.
(ssa_redirect_edge): Similarly
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.82
diff -c -p -r1.213.2.82 fold-const.c
*** fold-const.c 26 Mar 2004 16:22:07 -0000 1.213.2.82
--- fold-const.c 1 Apr 2004 17:03:59 -0000
*************** fold_relational_hi_lo (enum tree_code *c
*** 9072,9077 ****
--- 9072,9084 ----
TREE_TYPE (exp),
TREE_OPERAND (exp, 0),
TREE_OPERAND (exp, 1));
+
+ /* If we are in gimple form, then returning EXP would create
+ non-gimple expressions. Clearing it is safe and insures
+ we do not allow a non-gimple expression to escape. */
+ if (in_gimple_form)
+ exp = NULL;
+
return (retval ? retval : exp);
}
}
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.135
diff -c -p -r1.1.4.135 tree-optimize.c
*** tree-optimize.c 26 Mar 2004 16:22:28 -0000 1.1.4.135
--- tree-optimize.c 1 Apr 2004 17:04:01 -0000
*************** Boston, MA 02111-1307, USA. */
*** 52,57 ****
--- 52,58 ----
/* Global variables used to communicate with passes. */
int dump_flags;
bitmap vars_to_rename;
+ bool in_gimple_form;
/* The root of the compilation pass tree, once constructed. */
static struct tree_opt_pass *all_passes;
*************** tree_rest_of_compilation (tree fndecl, b
*** 522,529 ****
--- 523,537 ----
}
}
+ /* Note that the folders should only create gimple expressions.
+ This is a hack until the new folder is ready. */
+ in_gimple_form = 1;
+
/* Perform all tree transforms and optimizations. */
execute_pass_list (all_passes);
+
+ /* Note that the folders can create non-gimple expressions again. */
+ in_gimple_form = 1;
/* If the function has a variably modified type, there may be
SAVE_EXPRs in the parameter types. Their context must be set to
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.148
diff -c -p -r1.1.2.148 tree-ssa-ccp.c
*** tree-ssa-ccp.c 16 Mar 2004 22:31:55 -0000 1.1.2.148
--- tree-ssa-ccp.c 1 Apr 2004 17:04:04 -0000
*************** ccp_fold (tree stmt)
*** 806,811 ****
--- 806,816 ----
TREE_TYPE (rhs),
op0);
+ /* If we folded, but did not create an invariant, then we can not
+ use this expression. */
+ if (retval && ! is_gimple_min_invariant (retval))
+ return NULL;
+
/* If we could not fold the expression, but the arguments are all
constants and gimple values, then build and return the new
expression.
*************** ccp_fold (tree stmt)
*** 854,859 ****
--- 859,869 ----
TREE_TYPE (rhs),
op0, op1);
+ /* If we folded, but did not create an invariant, then we can not
+ use this expression. */
+ if (retval && ! is_gimple_min_invariant (retval))
+ return NULL;
+
/* If we could not fold the expression, but the arguments are all
constants and gimple values, then build and return the new
expression.
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.216
diff -c -p -r1.1.4.216 tree-ssa.c
*** tree-ssa.c 19 Mar 2004 02:07:25 -0000 1.1.4.216
--- tree-ssa.c 1 Apr 2004 17:04:06 -0000
*************** Boston, MA 02111-1307, USA. */
*** 53,63 ****
void
ssa_remove_edge (edge e)
{
! tree phi;
/* Remove the appropriate PHI arguments in E's destination block. */
! for (phi = phi_nodes (e->dest); phi; phi = TREE_CHAIN (phi))
! remove_phi_arg (phi, e->src);
remove_edge (e);
}
--- 53,66 ----
void
ssa_remove_edge (edge e)
{
! tree phi, next;
/* Remove the appropriate PHI arguments in E's destination block. */
! for (phi = phi_nodes (e->dest); phi; phi = next)
! {
! next = TREE_CHAIN (phi);
! remove_phi_arg (phi, e->src);
! }
remove_edge (e);
}
*************** ssa_remove_edge (edge e)
*** 69,82 ****
edge
ssa_redirect_edge (edge e, basic_block dest)
{
! tree phi;
tree list = NULL, *last = &list;
tree src, dst, node;
int i;
/* Remove the appropriate PHI arguments in E's destination block. */
! for (phi = phi_nodes (e->dest); phi; phi = TREE_CHAIN (phi))
{
i = phi_arg_from_edge (phi, e);
if (i < 0)
continue;
--- 72,87 ----
edge
ssa_redirect_edge (edge e, basic_block dest)
{
! tree phi, next;
tree list = NULL, *last = &list;
tree src, dst, node;
int i;
/* Remove the appropriate PHI arguments in E's destination block. */
! for (phi = phi_nodes (e->dest); phi; phi = next)
{
+ next = TREE_CHAIN (phi);
+
i = phi_arg_from_edge (phi, e);
if (i < 0)
continue;
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.180
diff -c -p -r1.342.2.180 tree.h
*** tree.h 26 Mar 2004 16:22:30 -0000 1.342.2.180
--- tree.h 1 Apr 2004 17:04:12 -0000
*************** typedef enum
*** 3757,3761 ****
--- 3757,3766 ----
extern int tree_node_counts[];
extern int tree_node_sizes[];
+
+ /* True if we are in gimple form and the actions of the folders need to
+ be restricted. False if we are not in gimple form and folding is not
+ restricted to creating gimple expressions. */
+ extern bool in_gimple_form;
#endif /* GCC_TREE_H */
jeff