This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PR 6212
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: mark at codesourcery dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 6 May 02 06:43:25 EDT
- Subject: Re: PR 6212
How did it work before? I know these things changed a lot, but still it
would be useful to know how we got it right in the past.
We didn't try to track the alignment of objects, but relied just on the
types, so there's really no comparison.
I think what you're saying is that we could assume that the value stored
in a T*, considered as an integer, is divisible by the alignment of T.
Is that right?
Yes.
That is a safe assumption only when the pointer is being dereferenced.
The C standard guarantees this property; you can't use a T* to access
something that is not a T, and a T must, by definition, be aligned as
required for a T.
If the pointer value is merely being read, the assumption does not hold,
Well, it's not "merely being read", but not being dereferenced either.
The relevant part of the testcase is:
void
fde_split (fde **probe, struct fde_vector *linear, struct fde_vector *erratic)
{
erratic->array[probe - linear->array] = 0;
}
To do this index computation, we do the subtraction, divide by the size
of the object being pointed to (POINTER_SIZE), then multiply by the size
of the element of ARRAY, also POINTER_SIZE. So we lose the fact that there
was the multiplication. However, both things being subtracted are known to
be multiples of POINTER_SIZE / BITS_PER_UNIT if we look at the type.
For example, we must not optimize:
(int)(T*)x % alignof(T)
to 0.
Since this is just in highest_pow2_factor, we wouldn't be.
It depends on the patch. I will have to make a judgement call.
It would be helpful if you post and begin testing a patch. Since it's
easy, please do this soon.
Well, what I tested was the following, plus the change to make that
function unsigned:
*** expr.c 16 Apr 2002 06:03:36 -0000 1.423.2.18
--- expr.c 6 May 2002 10:43:38 -0000
*************** highest_pow2_factor (exp)
*** 5903,5906 ****
--- 5903,5912 ----
c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
return MIN (c0, c1);
+
+ case PARM_DECL: case VAR_DECL: case RESULT_DECL:
+ /* If this is an object that is a pointer type, assume it is
+ properly aligned. */
+ if (POINTER_TYPE_P (TREE_TYPE (exp)))
+ return TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
default:
You should, in any case, fix this on the mainline quickly. There, you
can of course use a more invasive technique if you like.
Right, but the new tree node will be a lot of work to add, so I don't want
to rush into it. The above should work there too.