forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Lower memref.reinterpret_cast to EmitC #392
Open
cferry-AMD
wants to merge
2
commits into
feature/fused-ops
Choose a base branch
from
corentin.memref_reinterpret_cast
base: feature/fused-ops
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this represent
?
That does not look like valid C/C++ to me.
From what I understand from cppreference is that even a
reinterpret_cast
(reinterpret_cast<int[8]>(ar)) would be undefined behavior.Am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm wrong, this code introduces a C++ lvalue reference, like this:
which makes it "compilable" C++ code.
About the undefined behavior: this memref op will let us create any descriptor from any other memref descriptor, so I would expect undefined behavior could happen, but such behavior already existed in the original MLIR. Do you think this lowering is introducing otherwise avoidable undefined behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's undefined behavior while we are in the memref dialect because the dialect defines it as not being undefined.
On the C++ level, this clause of
reinterpret_cast
appliesAn glvalue expression of type T1 can be converted to reference to another type T2. The result is that of
*reinterpret_cast<T2*>(p)
, where p is a pointer of type “pointer to T1” to the object or function designated by expression. No temporary is created, no copy is made, no constructors or conversion functions are called. The resulting reference can only be accessed safely if it is type-accessible.Type accessibility
If a type T_ref is similar to any of the following types, an object of dynamic type T_obj is type-accessible through a glvalue of type T_ref:
If a program attempts to read or modify the stored value of an object through a glvalue) through which it is not type-accessible, the behavior is undefined.
Similar types
Informally, two types are similar if, ignoring top-level cv-qualification:
So to judge whether the access through the cast is fine (the cast itself is never UB), it depends on whether the element type of
int ar[2][5];
isint ar[2]
orint
. If it's the latter, then it would be the same as the element type ofint [8]
, which would makes both types similar and thus type-accessible.