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] Fix ICE in fold-const.c


On Mon, 17 May 2004, Andrew Pinski wrote:
> The front-ends are correctly converting it to be ! (a == 0) when passed
> to fold, the problem comes into play when trying to do a combine pass
> for tree-ssa, so combining c_1 = ! d_2 and d_2 = (bool)a_3 which gives
> ! (bool)a_3 and then passing that to fold which I assumed to do the
> right thing.  a is not of type boolean_type at all but integer_type.

Thanks, this is beginning to make sense.

Firstly, there's a mistake in your patch.  It's not TREE_CODE (arg0)
that you need to test but TREE_CODE (TREE_TYPE (arg0)), i.e.

	if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
	  arg0 = fold (TREE_OPERAND (t, 0));

and fold normally can assume that the operands to the current tree
node have already been folded.  This additional call to fold was one
of the things confusing me earlier.  However your explanation makes
it clear that it shouldn't be needed (unfolded operands aren't the
problem).

	if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
	  arg0 = TREE_OPERAND (t, 0);

However this is probably better written as

	/* The argument to invert_truthvalue must have Boolean type.  */
	if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
	  arg0 = fold_convert (boolean_type_node, arg0);


Ok for mainline with those changes, if it survives boostrapping and
regression tests on your machine.


If this doesn't also fix Joseph Myer's problems with single bit fields,
I'd be inclined to suggest that we might also consider removing the

	if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE)
	  abort ();

from invert_truthvalue.  The middle-end rarely checks for precise
tree types, and if the value has the correct mode that should often
be sufficient.  Indeed the above abort conflicts with the intention
of STRIP_NOPS et al., so there may be additional ICEs still lurking
in fold-const.c.

Thanks (and to Joseph) for taking the time to explain.

Roger
--


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