-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CIR] Upstream pointer subtraction handling #163306
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
9f2ec3c
Copy incubator tests
kimsh02 db85047
Stash
kimsh02 a3709f9
Clang-format
kimsh02 0ff0218
Stash
kimsh02 61bc256
Fix testcases
kimsh02 50412c3
Clang-format
kimsh02 52f0f44
Clang-format
kimsh02 de497b2
Apply coding style feedback
kimsh02 507edc2
Apply test and doc feedback
kimsh02 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
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
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,51 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll | ||
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s | ||
|
||
int addrcmp(const void* a, const void* b) { | ||
// CIR-LABEL: addrcmp | ||
// CIR: %[[R:.*]] = cir.ptr_diff | ||
// CIR: cir.cast integral %[[R]] : !s64i -> !s32i | ||
|
||
// LLVM-LABEL: define dso_local i32 @addrcmp( | ||
// LLVM: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i64 | ||
// LLVM: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i64 | ||
// LLVM: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]] | ||
// LLVM-NOT: sdiv | ||
// LLVM: trunc i64 %[[SUB]] to i32 | ||
|
||
// OGCG-LABEL: define dso_local i32 @addrcmp( | ||
// OGCG: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i64 | ||
// OGCG: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i64 | ||
// OGCG: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]] | ||
// OGCG-NOT: sdiv | ||
// OGCG: trunc i64 %[[SUB]] to i32 | ||
return *(const void**)a - *(const void**)b; | ||
} | ||
|
||
unsigned long long test_ptr_diff(int *a, int* b) { | ||
// CIR-LABEL: test_ptr_diff | ||
// CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!s32i> -> !s64i | ||
// CIR: %[[U:.*]] = cir.cast integral %[[D]] : !s64i -> !u64i | ||
// CIR: cir.return {{.*}} : !u64i | ||
|
||
// LLVM-LABEL: define dso_local i64 @test_ptr_diff( | ||
// LLVM: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// LLVM: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// LLVM: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]] | ||
// LLVM: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 4 | ||
// LLVM: store i64 %[[Q]], ptr %[[RETADDR:.*]], align | ||
// LLVM: %[[RETLOAD:.*]] = load i64, ptr %[[RETADDR]], align | ||
// LLVM: ret i64 %[[RETLOAD]] | ||
|
||
// OGCG-LABEL: define dso_local i64 @test_ptr_diff( | ||
// OGCG: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// OGCG: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// OGCG: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]] | ||
// OGCG: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 4 | ||
// OGCG: ret i64 %[[Q]] | ||
return a - b; | ||
} | ||
kimsh02 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,33 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll | ||
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG | ||
|
||
typedef unsigned long size_type; | ||
|
||
size_type size(unsigned long *_start, unsigned long *_finish) { | ||
// CIR-LABEL: cir.func dso_local @_Z4sizePmS_ | ||
// CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!u64i> -> !s64i | ||
// CIR: %[[U:.*]] = cir.cast integral %[[D]] : !s64i -> !u64i | ||
// CIR: cir.return {{.*}} : !u64i | ||
|
||
// LLVM-LABEL: define dso_local {{.*}}i64 @_Z4sizePmS_( | ||
// LLVM: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// LLVM: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// LLVM: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]] | ||
// LLVM: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 8 | ||
// LLVM: store i64 %[[Q]], ptr %[[RETADDR:.*]], align | ||
// LLVM: %[[RET:.*]] = load i64, ptr %[[RETADDR]], align | ||
// LLVM: ret i64 %[[RET]] | ||
|
||
// OGCG-LABEL: define dso_local {{.*}}i64 @_Z4sizePmS_( | ||
// OGCG: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// OGCG: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i64 | ||
// OGCG: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]] | ||
// OGCG: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 8 | ||
// OGCG: ret i64 %[[Q]] | ||
|
||
return static_cast<size_type>(_finish - _start); | ||
} |
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.