-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[IR] Require DataLayout for pointer cast elimination #162279
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
Conversation
isEliminableCastPair() currently tries to support elimination of ptrtoint/inttoptr cast pairs by assuming that the maximum possible pointer size is 64 bits. Of course, this is no longer the case nowadays. This PR changes isEliminableCastPair() to accept an optional DataLayout argument, which is required to eliminate pointer casts. This means that we no longer eliminate these cast pairs during ConstExpr construction, and instead only do it during DL-aware constant folding. This had a lot of annoying fallout on tests, most of which I've addressed in advance of this change.
|
||
//------------------------------------------------------------------------------ | ||
|
||
char *one_var(unsigned long offset) { |
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.
After spending way too much time updating manually updating these tests, I decided to delete them altogether. I don't think they add any value over the generic tests (using non-constants) higher up, and just end up testing details of IRBuilder's constant folding behavior.
✅ With the latest revision this PR passed the C/C++ code formatter. |
ret void | ||
} | ||
|
||
define void @stores_ptrtoint_constexpr() { |
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.
Deleting this function seemed like the best way to preserve the overall test intent. Previously this ended up folding during IR construction, so the constant expression here was effectively not present at all.
; CHECK-NEXT: ret ptr addrspace(1) [[PTR]] | ||
; CHECK-NEXT: [[INT:%.*]] = ptrtoint ptr addrspace(1) [[PTR]] to i64 | ||
; CHECK-NEXT: [[PTR2:%.*]] = inttoptr i64 [[INT]] to ptr addrspace(1) | ||
; CHECK-NEXT: ret ptr addrspace(1) [[PTR2]] |
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.
This illustrates the miscompile.
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: call void @use.i32(i32 0) | ||
; CHECK-NEXT: [[AND_2:%.*]] = and i32 20, [[A:%.*]] | ||
; CHECK-NEXT: [[AND_2:%.*]] = and i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), [[A:%.*]] |
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 wasn't sure what to do with this test. Previously the constant expression here just folded away, so it wasn't really testing constant expressions, as the test name indicates. So I decided to leave this as-is.
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.
LG
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.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/23679 Here is the relevant piece of the build log for the reference
|
isEliminableCastPair() currently tries to support elimination of ptrtoint/inttoptr cast pairs by assuming that the maximum possible pointer size is 64 bits. Of course, this is no longer the case nowadays.
This PR changes isEliminableCastPair() to accept an optional DataLayout argument, which is required to eliminate pointer casts.
This means that we no longer eliminate these cast pairs during ConstExpr construction, and instead only do it during DL-aware constant folding. This had a lot of annoying fallout on tests, most of which I've addressed in advance of this change.