[LLVMdev] Narrowing pointers to storage width from GPR width

Burke, Max mburke at ea.com
Wed Feb 25 10:31:29 PST 2009


I have a platform that I am targeting that has 64-bit general purpose
registers but uses 32-bit pointers (ie, sizeof(void*) == 4) but
unfortunately it also requires that the top 32-bits of the pointer value
be clear. This sometimes becomes a problem with certain pointer
calculations such as using a 32-bit negative value for indexing into an
array can cause the upper bits to be set, generating access violations
when used.

My first thought for fixing this issue was to modify GetElementPtr and
IntToPtr to perform pointer math on register width values and truncating
them down to the required size as specified in the platform's target
data string but all of these added operations disappear at optimization
time. 

The current hack that I have in place is to force a clear of the upper
32-bits before every load and store which works from a correctness point
of view but does horrible things to code size. I was thinking also of
modifying the front end to use i32's as the storage type for all
pointers and converting to/from the appropriate pointer type as
necessary but I am hesitant because I'm not sure of the potential impact
it may have on code generation/optimization.

Does anyone have tips on how to take care of this properly? 

-Max




More information about the llvm-dev mailing list