Setting alignment for a ByVal argument

Hi,

If I want a particular alignment on a ByVal argument, should I specify
it as a function attribute, or should I also add the attribute to
every callsite that calls that function.

Thanks,

Arushi

Hi Arushi,

If I want a particular alignment on a ByVal argument, should I specify
it as a function attribute, or should I also add the attribute to
every callsite that calls that function.

in theory you should do both. For example, if the call is an indirect call
(i.e. to a function pointer where the function is not known) then it should
be clear that you need to put the attribute on the callsite. Likewise, when
code is being generated for the function, there is only one place where the
code generators can find out what alignment the incoming argument has: the
attribute on the function argument. Hopefully these examples show why you
should put it both on the function and any call sites. That said, if you
put it only on the function the code generators are usually friendly to you
and will understand that you meant to have it on call sites too. But if I
were you I wouldn't rely on this.

Ciao,

Duncan.

Hi,
Thanks for the help. I tried this out, but on x86_64 and with llvm 2.6
and llvm-gcc 4.2.1, I dont seem to get an aligned variable.

This is the function definition that I have

define internal fastcc void @walksub(%struct.hgstruct* noalias
nocapture sret %agg.result, %struct.node* %p, double %dsq,
%struct.hgstruct* byval align 64 %hg, i32 %level) nounwind {

And these are the call sites,

call fastcc void @walksub(%struct.hgstruct* noalias sret %2,
%struct.node* %tmp399, double %tmp398, %struct.hgstruct* byval align
64 %1, i32 0) nounwind

call fastcc void @walksub(%struct.hgstruct* notcc void
@walksub(%struct.hgstruct* noalias sret %2, %struct.node* %tmp399,
double %tmp398, %struct.hgstruct* byval align 64 %1, i32 0) nounwind

The value that I get for %hg, is 0x7fffe0e34a20 which is not aligned
to 64 byte boundary.

Any pointers on where I could be wrong?

Thanks,
Arushi

Hi Arushi,

Thanks for the help. I tried this out, but on x86_64 and with llvm 2.6
and llvm-gcc 4.2.1, I dont seem to get an aligned variable.

does it work with llvm-2.7 (just released)?

Ciao,

Duncan.

I could not get the same .bc file work with llvm 2.7 on x86_64 either.
This is the address I got for a byval argument meant to be aligned to
64byte boundary.

0x7fff3f0ae030

Any more pointers?

Arushi

PS: Is the IR representation in 2.7 any different, that I should not
use the same bitcode file.

Hi Arushi,

I could not get the same .bc file work with llvm 2.7 on x86_64 either.
This is the address I got for a byval argument meant to be aligned to
64byte boundary.

0x7fff3f0ae030

Any more pointers?

at this point I suggest you file a bugreport and provide a testcase there.

PS: Is the IR representation in 2.7 any different, that I should not
use the same bitcode file.

Bitcode from 2.6 is supposed to work with 2.7.

Ciao,

Duncan.