-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ConstantFold] Fold inttoptr, ptrtoaddr to bitcast #161087
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
267d813
[ConstantFold] inttoptr, ptrtoaddr is valid cast pair
XChy 5513266
optimize inttoptr, ptrtoaddr
XChy fbdea3c
fix testcases
XChy 7ac9346
format
XChy d6fda59
fix typo
XChy b1ccc78
fix typo
XChy 9eb64c9
add tests
XChy d451c18
add address space
XChy 1101f3b
move tests
XChy 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
target datalayout = "p1:64:64:64:32" | ||
|
||
define i32 @ptrtoaddr_inttoptr_arg(i32 %a) { | ||
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr_arg( | ||
; CHECK-SAME: i32 [[A:%.*]]) { | ||
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[A]] to i64 | ||
; CHECK-NEXT: [[TOPTR:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(1) | ||
; CHECK-NEXT: [[TOADDR:%.*]] = ptrtoaddr ptr addrspace(1) [[TOPTR]] to i32 | ||
; CHECK-NEXT: ret i32 [[TOADDR]] | ||
; | ||
%toptr = inttoptr i32 %a to ptr addrspace(1) | ||
%toaddr = ptrtoaddr ptr addrspace(1) %toptr to i32 | ||
ret i32 %toaddr | ||
} | ||
|
||
define i32 @ptrtoaddr_inttoptr() { | ||
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr() { | ||
; CHECK-NEXT: ret i32 -1 | ||
; | ||
ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i32 -1 to ptr addrspace(1)) to i32) | ||
} | ||
|
||
define i32 @ptrtoaddr_inttoptr_diff_size1() { | ||
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr_diff_size1() { | ||
; CHECK-NEXT: ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i64 -1 to ptr addrspace(1)) to i32) | ||
; | ||
ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i64 -1 to ptr addrspace(1)) to i32) | ||
} | ||
|
||
define i32 @ptrtoaddr_inttoptr_diff_size2() { | ||
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr_diff_size2() { | ||
; CHECK-NEXT: ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i16 -1 to ptr addrspace(1)) to i32) | ||
; | ||
ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i16 -1 to ptr addrspace(1)) to i32) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, we can make some of these fold, but we should really change the isEliminableCastPair() API to accept DataLayout for that. Leaving these cases alone is fine for now. |
||
|
||
define i64 @ptrtoaddr_inttoptr_noas1() { | ||
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas1() { | ||
; CHECK-NEXT: ret i64 1 | ||
; | ||
ret i64 ptrtoaddr (ptr getelementptr (i8, ptr null, i64 1) to i64) | ||
} | ||
|
||
define i64 @ptr2addr2_inttoptr_noas2() { | ||
; CHECK-LABEL: define i64 @ptr2addr2_inttoptr_noas2() { | ||
; CHECK-NEXT: ret i64 123 | ||
; | ||
ret i64 ptrtoaddr (ptr inttoptr (i64 123 to ptr) to i64) | ||
} | ||
|
||
define i64 @ptrtoaddr_inttoptr_noas_diff_size1() { | ||
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas_diff_size1() { | ||
; CHECK-NEXT: ret i64 ptrtoaddr (ptr inttoptr (i32 -1 to ptr) to i64) | ||
; | ||
ret i64 ptrtoaddr (ptr inttoptr (i32 -1 to ptr) to i64) | ||
} | ||
|
||
define i64 @ptrtoaddr_inttoptr_noas_diff_size2() { | ||
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas_diff_size2() { | ||
; CHECK-NEXT: ret i64 ptrtoaddr (ptr inttoptr (i128 -1 to ptr) to i64) | ||
; | ||
ret i64 ptrtoaddr (ptr inttoptr (i128 -1 to ptr) to i64) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.