-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9f2ec3c
Copy incubator tests
monthdev db85047
Stash
monthdev a3709f9
Clang-format
monthdev 0ff0218
Stash
monthdev 61bc256
Fix testcases
monthdev 50412c3
Clang-format
monthdev 52f0f44
Clang-format
monthdev de497b2
Apply coding style feedback
monthdev 507edc2
Apply test and doc feedback
monthdev 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,35 @@ | ||
| // 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.ll | ||
| // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s | ||
monthdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| 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 | ||
monthdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // LLVM: store i64 %[[Q]], ptr %[[RETADDR:.*]], align | ||
| // LLVM: %[[RETLOAD:.*]] = load i64, ptr %[[RETADDR]], align | ||
| // LLVM: ret i64 %[[RETLOAD]] | ||
| return a - b; | ||
| } | ||
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,13 @@ | ||
| // 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 | ||
|
|
||
| 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 | ||
|
|
||
| return static_cast<size_type>(_finish - _start); | ||
| } | ||
monthdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.