[PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 11:29:50 PDT 2016

yaxunl marked an inline comment as done.
yaxunl added a comment.

In https://reviews.llvm.org/D23361#512729, @Anastasia wrote:

> I think Clang is supposed to generate the IR specific to the target architecture. It seems strange to ignore the pointer size. I am not sure if it might lead to some issues for the backends.

This change only affects AMDGCN target which has different pointer size for different address spaces. There is no change for other targets.

For AMDGCN target, since there can be only one definition for size_t type, it has to be 64 bit to accommodate all pointers.

For operations not involving pointers, this is fine since it does not matter whether size_t is i32 or i64.

For operations involving pointers, it only affects ptrtoint instruction, which allows a pointer to be casted to any integer. If the integer size is larger than the pointer size, it is zero extended. If the integer is smaller than the pointer size, it is truncated.

When clang casts a pointer to size_t, there are two cases:

1. non-private pointers: before this change, it was casted to i32, which is wrong. now it is casted to i64 correctly.

2. private pointer: before this change, it was casted to i32, now it is casted to i64. It is still correct. Backend should be able to optimize these instructions.


More information about the cfe-commits mailing list