-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[PreISelIntrinsicLowering] Look through ptrtoint for a constant (e.g. global ptr) when trying to produce memset_pattern16 #129220
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
Closed
asb
wants to merge
7
commits into
llvm:main
from
asb:2025q1-preiselintrinsiclowering-memset-pattern-ptrpat
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a313322
[PreISelIntrinsicLowering][test] Precommit test for failure to select…
asb 7dea145
[PreISelIntrinsicLowering] Support producing memset_pattern16 when lo…
asb cb47c53
Merge remote-tracking branch 'origin/main' into 2025q1-preiselintrins…
asb 8fd2d02
Update test case to no longer assume global ptrs arg is loaded from g…
asb bd31315
Look through a ptrtoint cast for a constant (e.g. global ptr)
asb 237c0bf
Merge remote-tracking branch 'origin/main' into 2025q1-preiselintrins…
asb 2b6d262
Merge remote-tracking branch 'origin/main' into 2025q1-preiselintrins…
asb 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 |
|---|---|---|
|
|
@@ -2,13 +2,16 @@ | |
| ; RUN: opt -mtriple=x86_64-apple-darwin10.0.0 -passes=pre-isel-intrinsic-lowering -S -o - %s | FileCheck %s | ||
|
|
||
| ;. | ||
| ; CHECK: @G = global i32 5 | ||
| ; CHECK: @.memset_pattern = private unnamed_addr constant [2 x i64] [i64 -6148895925951734307, i64 -6148895925951734307], align 16 | ||
| ; CHECK: @.memset_pattern.1 = private unnamed_addr constant [2 x i64] [i64 4614256656552045848, i64 4614256656552045848], align 16 | ||
| ; CHECK: @.memset_pattern.2 = private unnamed_addr constant [8 x i16] [i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555], align 16 | ||
| ; CHECK: @.memset_pattern.3 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ; CHECK: @.memset_pattern.4 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ; CHECK: @.memset_pattern.2 = private unnamed_addr constant [2 x ptr] [ptr @G, ptr @G], align 16 | ||
| ; CHECK: @.memset_pattern.3 = private unnamed_addr constant [2 x ptr] [ptr @G, ptr @G], align 16 | ||
| ; CHECK: @.memset_pattern.4 = private unnamed_addr constant [8 x i16] [i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555, i16 -21555], align 16 | ||
| ; CHECK: @.memset_pattern.5 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ; CHECK: @.memset_pattern.6 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ; CHECK: @.memset_pattern.7 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ; CHECK: @.memset_pattern.8 = private unnamed_addr constant i128 -113427455635030943652277463699152839203, align 16 | ||
| ;. | ||
| define void @memset_pattern_i128_1_dynvalue(ptr %a, i128 %value) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i128_1_dynvalue( | ||
|
|
@@ -31,7 +34,7 @@ define void @memset_pattern_i128_1_dynvalue(ptr %a, i128 %value) nounwind { | |
| define void @memset_pattern_i128_1(ptr %a, i128 %value) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i128_1( | ||
| ; CHECK-SAME: ptr [[A:%.*]], i128 [[VALUE:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.3, i64 16) | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.5, i64 16) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i128 u0xaaaaaaaabbbbbbbbccccccccdddddddd, i64 1, i1 false) | ||
|
|
@@ -59,7 +62,7 @@ define void @memset_pattern_i128_1_nz_as(ptr addrspace(1) %a, i128 %value) nounw | |
| define void @memset_pattern_i128_1_align_attr(ptr align(16) %a, i128 %value) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i128_1_align_attr( | ||
| ; CHECK-SAME: ptr align 16 [[A:%.*]], i128 [[VALUE:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr align 16 [[A]], ptr @.memset_pattern.4, i64 16) | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr align 16 [[A]], ptr @.memset_pattern.6, i64 16) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| tail call void @llvm.experimental.memset.pattern(ptr align(16) %a, i128 u0xaaaaaaaabbbbbbbbccccccccdddddddd, i64 1, i1 false) | ||
|
|
@@ -69,7 +72,7 @@ define void @memset_pattern_i128_1_align_attr(ptr align(16) %a, i128 %value) nou | |
| define void @memset_pattern_i128_16(ptr %a) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i128_16( | ||
| ; CHECK-SAME: ptr [[A:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.5, i64 256) | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.7, i64 256) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i128 u0xaaaaaaaabbbbbbbbccccccccdddddddd, i64 16, i1 false) | ||
|
|
@@ -80,7 +83,7 @@ define void @memset_pattern_i128_x(ptr %a, i64 %x) nounwind { | |
| ; CHECK-LABEL: define void @memset_pattern_i128_x( | ||
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[X:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 16, [[X]] | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.6, i64 [[TMP1]]) | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.8, i64 [[TMP1]]) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i128 u0xaaaaaaaabbbbbbbbccccccccdddddddd, i64 %x, i1 false) | ||
|
|
@@ -110,7 +113,7 @@ define void @memset_pattern_i16_x(ptr %a, i64 %x) nounwind { | |
| ; CHECK-LABEL: define void @memset_pattern_i16_x( | ||
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[X:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 2, [[X]] | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.2, i64 [[TMP1]]) | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.4, i64 [[TMP1]]) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i16 u0xabcd, i64 %x, i1 false) | ||
|
|
@@ -144,6 +147,56 @@ define void @memset_pattern_i64_128_tbaa(ptr %a) nounwind { | |
| !7 = !{!"omnipotent char", !8, i64 0} | ||
| !8 = !{!"Simple C++ TBAA"} | ||
|
|
||
| @G = global i32 5 | ||
|
|
||
| define void @memset_pattern_i64_16_fromptr(ptr %a) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i64_16_fromptr( | ||
| ; CHECK-SAME: ptr [[A:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr @G to i64 | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.2, i64 128) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| %1 = ptrtoint ptr @G to i64 | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i64 %1, i64 16, i1 false) | ||
| ret void | ||
| } | ||
|
|
||
| define void @memset_pattern_i64_x_fromptr(ptr %a, i64 %x) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i64_x_fromptr( | ||
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[X:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr @G to i64 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = mul i64 8, [[X]] | ||
| ; CHECK-NEXT: call void @memset_pattern16(ptr [[A]], ptr @.memset_pattern.3, i64 [[TMP2]]) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| %1 = ptrtoint ptr @G to i64 | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i64 %1, i64 %x, i1 false) | ||
| ret void | ||
| } | ||
|
|
||
| ; memset_pattern16 shouldn't be used for this example (at least not by just | ||
| ; creating a constantarray global at compile time), as the ptr isn't constant. | ||
| define void @memset_pattern_i64_x_fromnonconstptr(ptr %a, i64 %x, ptr %p) nounwind { | ||
| ; CHECK-LABEL: define void @memset_pattern_i64_x_fromnonconstptr( | ||
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[X:%.*]], ptr [[P:%.*]]) #[[ATTR0]] { | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64 | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 0, [[X]] | ||
| ; CHECK-NEXT: br i1 [[TMP2]], label %[[SPLIT:.*]], label %[[LOADSTORELOOP:.*]] | ||
| ; CHECK: [[LOADSTORELOOP]]: | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = phi i64 [ 0, [[TMP0:%.*]] ], [ [[TMP5:%.*]], %[[LOADSTORELOOP]] ] | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP3]] | ||
| ; CHECK-NEXT: store i64 [[TMP1]], ptr [[TMP4]], align 1 | ||
| ; CHECK-NEXT: [[TMP5]] = add i64 [[TMP3]], 1 | ||
| ; CHECK-NEXT: [[TMP6:%.*]] = icmp ult i64 [[TMP5]], [[X]] | ||
| ; CHECK-NEXT: br i1 [[TMP6]], label %[[LOADSTORELOOP]], label %[[SPLIT]] | ||
| ; CHECK: [[SPLIT]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| %1 = ptrtoint ptr %p to i64 | ||
| tail call void @llvm.experimental.memset.pattern(ptr %a, i64 %1, i64 %x, i1 false) | ||
| ret void | ||
|
Comment on lines
+195
to
+197
Contributor
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. (finding the new no-required mangling suffix behavior confusing) Could instcombine fold this to pull the cast in, and adjust the call signature? |
||
| } | ||
|
|
||
| ;. | ||
| ; CHECK: attributes #[[ATTR0]] = { nounwind } | ||
| ; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: write) } | ||
|
|
||
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.