Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CodeGen] Fix address space of result pointer type of array decay cast op #812

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

seven-mile
Copy link
Collaborator

There are two occurrences of cir.cast(array_to_ptrdecay, ...) that drop address spaces unexpectedly for its result pointer type. This PR fixes them with the source address space.

// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>

@Lancern
Copy link
Member

Lancern commented Sep 2, 2024

Maybe we should check array_to_ptrdecay does not change the address space in CastOp::verify ?

@seven-mile
Copy link
Collaborator Author

@Lancern Yes, it's #813 ; )

@Lancern
Copy link
Member

Lancern commented Sep 2, 2024

@Lancern Yes, it's #813 ; )

Seems like #813 only covers bitcast and does not cover array_to_ptrdecay. Am I missing something?

@seven-mile
Copy link
Collaborator Author

Indeed! I'm mistaken. Let me include it in this PR.

Copy link
Member

@Lancern Lancern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@bcardosolopes bcardosolopes merged commit 016405c into llvm:main Sep 9, 2024
6 checks passed
bcardosolopes pushed a commit that referenced this pull request Sep 10, 2024
…on (#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…y cast op (llvm#812)

There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
drop address spaces unexpectedly for its result pointer type. This PR
fixes them with the source address space.

```mlir
// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
```
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…on (llvm#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

llvm#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…y cast op (llvm#812)

There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
drop address spaces unexpectedly for its result pointer type. This PR
fixes them with the source address space.

```mlir
// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
```
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…on (llvm#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

llvm#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…y cast op (llvm#812)

There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
drop address spaces unexpectedly for its result pointer type. This PR
fixes them with the source address space.

```mlir
// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
```
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…on (llvm#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

llvm#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…y cast op (llvm#812)

There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
drop address spaces unexpectedly for its result pointer type. This PR
fixes them with the source address space.

```mlir
// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
```
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…on (llvm#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

llvm#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
lanza pushed a commit that referenced this pull request Nov 5, 2024
…y cast op (#812)

There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
drop address spaces unexpectedly for its result pointer type. This PR
fixes them with the source address space.

```mlir
// Before
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
// After
%1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
```
lanza pushed a commit that referenced this pull request Nov 5, 2024
…on (#813)

Currently some bitcasts would silently change the address space of
source pointer type, which hides some miscompilations of pointer type in
CIR.

#812 is an example. The address space in result pointer type is dropped,
but the bitcast later keep the type consistency no matter what the
result type is. Such bitcast is commonly emitted in CodeGen.

CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
mismatch between address spaces. This PR adds this verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants