Problem with induction variables optimization pass

2011-04-14 Thread Camo Johnson
  
Hello,

I'm currently writing a gcc 4.4.5 backend for an 18 bit architecture.
I have a c-project with some thousand lines of code. Without optimizations it 
compiles. But with -O1 and -O2 I encounter a problem in the induction variables 
optimization pass.
The main issue is, that a temporary variable is created which works as a memory 
reference but is a 36 bit value (SImode). This results in an error at explow.c 
line 326, because pointers have to be 18 bit wide (HImode).
The code at this position is:

rtx
convert_memory_address (enum machine_mode to_mode ATTRIBUTE_UNUSED, rtx x)
{
#ifndef POINTERS_EXTEND_UNSIGNED
gcc_assert (GET_MODE (x) == to_mode || GET_MODE (x) == VOIDmode);

This asserts because x has mode SI and to_mode is Pmode/HImode.

I used the -fdump-tree-all option and in the source.c.126t.final_cleanup file I 
found the following:

isr00 ()
{
unsigned int ivtmp.112;
unsigned int D.3690;
long unsigned int D.3683;
unsigned int ivtmp.105;
unsigned int ivtmp.104;
unsigned int prephitmp.91;
unsigned int length;
unsigned int D.1415;
struct usb * usb0.0;

…

:
D.3683 = (long unsigned int) ivtmp.105 + (long unsigned int) ((unsigned int *) 
(long unsigned int) usb0.0 + 320);
spi_temporary_data[ivtmp.112] = [bit_and_expr] (unsigned char) (MEM[base: 
D.3683] >> 8) & 255;
spi_temporary_data[ivtmp.112 + 1] = [bit_and_expr] (unsigned char) MEM[base: 
D.3683] & 255

The problem is the D.3683 variable. The casts in the assignment for this 
variable are kind of senseless, because ivtmp.105 is unsigned int (18 bit), 
usb0.0 is a pointer which is also only 18 bit.

I checked the source files and I think the main problem is the use of sizetype 
in several locations working with addresses. sizetype is defined as long 
unsigned int and results in SImode when used. I found 3 code positions with an 
input tree mode of HImode where the use of sizetype or size_type_node results 
in 
a tree node with SImode:

tree-ssa-address.c line 414
here parts->index becomes a SImode tree node

static void
add_to_parts (struct mem_address *parts, tree elt)
{
tree type;

if (!parts->index)
{
parts->index = fold_convert (sizetype, elt);
return;
}

tree-ssa-address.c line 547
here part becomes a SImode tree node

static void
addr_to_parts (aff_tree *addr, struct mem_address *parts, bool speed)
{
...
/* Then try to process the remaining elements.  */
for (i = 0; i < addr->n; i++)
{
part = fold_convert (sizetype, addr->elts[i].val);
...
}

tree.cline 8332
here t becomes a SImode tree node

signed_or_unsigned_type_for (int unsignedp, tree type)
{
tree t = type;
if (POINTER_TYPE_P (type))
t = size_type_node;

if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
return t;
  
return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
}



As a solution, I tried to replace those 3 sizetype uses with 
global_trees[TI_UINTHI_TYPE]. So the relevant lines look like this:

parts->index = fold_convert (global_trees[TI_UINTHI_TYPE] /*sizetype*/, elt);
part = fold_convert (global_trees[TI_UINTHI_TYPE] /*sizetype*/, 
addr->elts[i].val);
t = global_trees[TI_UINTHI_TYPE] /*size_type_node*/;

With those changes, the compilation comes farther but crashes on the following 
gcc_assert:
tree.cline 3312function build2_stat

if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
&& INTEGRAL_TYPE_P (TREE_TYPE (arg1))
&& useless_type_conversion_p (sizetype, TREE_TYPE (arg1)));

If I comment out the "&& useless_type_conversion_p (sizetype, TREE_TYPE 
(arg1))" 
part the compilation works. I know its bad, but I don't know how to replace the 
sizetype in this case so that the assert doesn't happen.


I'm aware of the fact that those fixes would result in errors with other 
architectures. But just for my "strange 18 bit" architecture, is this ok? Might 
there be problems in some cases? Why is sizetype used in this positions 
anyways? 
Wouldn't it be better to somehow use the input tree type instead of sizetype?

I hope the description of the problem is understandable.

Regards,
Eric Neumann


gcc-4.5-20110414 is now available

2011-04-14 Thread gccadmin
Snapshot gcc-4.5-20110414 is now available on
  ftp://gcc.gnu.org/pub/gcc/snapshots/4.5-20110414/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 4.5 SVN branch
with the following options: svn://gcc.gnu.org/svn/gcc/branches/gcc-4_5-branch 
revision 172460

You'll find:

 gcc-4.5-20110414.tar.bz2 Complete GCC (includes all of below)

  MD5=99afbb908da4bed45d0553413d268ea7
  SHA1=10182f834ec6d8e6eca2e69f4924010d4153f02d

 gcc-core-4.5-20110414.tar.bz2C front end and core compiler

  MD5=106576d9f0199aabf4502595df7a4e2f
  SHA1=d040f3598668eb09ccffd5ce8afe1df06ee184cd

 gcc-ada-4.5-20110414.tar.bz2 Ada front end and runtime

  MD5=ade664262a1ba3ffe225736015f9838c
  SHA1=543db57ab41df3170abbd7a3fc0267543a0470b8

 gcc-fortran-4.5-20110414.tar.bz2 Fortran front end and runtime

  MD5=cb08be45a9076ede7f07df09b94b69cb
  SHA1=214d107466f0bd16d244656124e6c11ccee4a2c1

 gcc-g++-4.5-20110414.tar.bz2 C++ front end and runtime

  MD5=afba04145c112809cd53d38b1acb66fb
  SHA1=107dccf52b8124b58f824a4b81a5c544e79f2251

 gcc-go-4.5-20110414.tar.bz2  Go front end and runtime

  MD5=c96ce705cc9c31780a66340d63bc14fc
  SHA1=89758e132e13fbf5ae60ea3087262554164abc21

 gcc-java-4.5-20110414.tar.bz2Java front end and runtime

  MD5=8665930a2a11f2a7e744e0d952836943
  SHA1=37f5af0540907f6c2f0e71762e51ab6e2a02bd37

 gcc-objc-4.5-20110414.tar.bz2Objective-C front end and runtime

  MD5=a94a001b90d1b1fa8ba67166a0f27e7d
  SHA1=d1cd7e078675bf18eb47a95633e5f9049104ff5d

 gcc-testsuite-4.5-20110414.tar.bz2   The GCC testsuite

  MD5=478c563e98b13ef150529bb851b83a21
  SHA1=1e6d4fb1443ae4c1eded330f278a395ed1eff242

Diffs from 4.5-20110407 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-4.5
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.