-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[DirectX] Legalize memcpy #139173
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
[DirectX] Legalize memcpy #139173
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a23c221
Legalize memcpy
Icohedron 6ab5c90
Apply clang-format
Icohedron 8d12237
Specify return type of lambda expression
Icohedron b44152e
Replace llvm_unreachable with assert
Icohedron 426f0d3
Add a comment for ByteLength == 0 case of memcpy
Icohedron a6c4ce5
Rename removeMemCpy to legalizeMemCpy
Icohedron cb67e16
Remove lifetime markers from test
Icohedron 2212ea8
Add a memcpy test for arrays of 3 ints
Icohedron 41ac47e
Use InBoundsGEP instead of GEP
Icohedron a761a05
Remove memcpy test on arrays of vectors
Icohedron d606d63
Add support for mismatched array sizes
Icohedron 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,154 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -dxil-legalize -dxil-finalize-linkage -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
|
||
define void @replace_int_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_int_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [1 x i32], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [1 x i32], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[GEP]], align 4 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store i32 [[TMP3]], ptr [[GEP1]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [1 x i32], align 4 | ||
%2 = alloca [1 x i32], align 4 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 4 dereferenceable(4) %2, ptr align 4 dereferenceable(4) %1, i32 4, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_3int_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_3int_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [3 x i32], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [3 x i32], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[GEP]], align 4 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store i32 [[TMP3]], ptr [[GEP1]], align 4 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[GEP2]], align 4 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store i32 [[TMP4]], ptr [[GEP3]], align 4 | ||
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 2 | ||
; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[GEP4]], align 4 | ||
; CHECK-NEXT: [[GEP5:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 2 | ||
; CHECK-NEXT: store i32 [[TMP5]], ptr [[GEP5]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [3 x i32], align 4 | ||
%2 = alloca [3 x i32], align 4 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 4 dereferenceable(12) %2, ptr align 4 dereferenceable(12) %1, i32 12, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_mismatched_size_int_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_mismatched_size_int_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [2 x i32], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [3 x i32], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[GEP]], align 4 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store i32 [[TMP3]], ptr [[GEP1]], align 4 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[GEP2]], align 4 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store i32 [[TMP4]], ptr [[GEP3]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [2 x i32], align 4 | ||
%2 = alloca [3 x i32], align 4 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 4 dereferenceable(12) %2, ptr align 4 dereferenceable(8) %1, i32 8, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_int16_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_int16_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [2 x i16], align 2 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [2 x i16], align 2 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i16, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load i16, ptr [[GEP]], align 2 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i16, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store i16 [[TMP3]], ptr [[GEP1]], align 2 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i16, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load i16, ptr [[GEP2]], align 2 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds i16, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store i16 [[TMP4]], ptr [[GEP3]], align 2 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [2 x i16], align 2 | ||
%2 = alloca [2 x i16], align 2 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 2 dereferenceable(4) %2, ptr align 2 dereferenceable(4) %1, i32 4, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_float_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_float_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [2 x float], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [2 x float], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds float, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[GEP]], align 4 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds float, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store float [[TMP3]], ptr [[GEP1]], align 4 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds float, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load float, ptr [[GEP2]], align 4 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds float, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store float [[TMP4]], ptr [[GEP3]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [2 x float], align 4 | ||
%2 = alloca [2 x float], align 4 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 4 dereferenceable(8) %2, ptr align 4 dereferenceable(8) %1, i32 8, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_double_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_double_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [2 x double], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [2 x double], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[GEP]], align 8 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds double, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store double [[TMP3]], ptr [[GEP1]], align 8 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load double, ptr [[GEP2]], align 8 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds double, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store double [[TMP4]], ptr [[GEP3]], align 8 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [2 x double], align 4 | ||
%2 = alloca [2 x double], align 4 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 4 dereferenceable(8) %2, ptr align 4 dereferenceable(8) %1, i32 16, i1 false) | ||
ret void | ||
} | ||
|
||
define void @replace_half_memcpy_test() #0 { | ||
; CHECK-LABEL: define void @replace_half_memcpy_test( | ||
; CHECK-SAME: ) #[[ATTR0]] { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca [2 x half], align 2 | ||
; CHECK-NEXT: [[TMP2:%.*]] = alloca [2 x half], align 2 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds half, ptr [[TMP1]], i32 0 | ||
; CHECK-NEXT: [[TMP3:%.*]] = load half, ptr [[GEP]], align 2 | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds half, ptr [[TMP2]], i32 0 | ||
; CHECK-NEXT: store half [[TMP3]], ptr [[GEP1]], align 2 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds half, ptr [[TMP1]], i32 1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = load half, ptr [[GEP2]], align 2 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr inbounds half, ptr [[TMP2]], i32 1 | ||
; CHECK-NEXT: store half [[TMP4]], ptr [[GEP3]], align 2 | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = alloca [2 x half], align 2 | ||
%2 = alloca [2 x half], align 2 | ||
call void @llvm.memcpy.p0.p0.i32(ptr nonnull align 2 dereferenceable(4) %2, ptr align 2 dereferenceable(4) %1, i32 4, i1 false) | ||
ret void | ||
} | ||
Icohedron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
attributes #0 = {"hlsl.export"} | ||
|
||
declare void @llvm.memcpy.p0.p2.i32(ptr noalias, ptr addrspace(2) noalias readonly, i32, i1) | ||
declare void @llvm.memcpy.p0.p0.i32(ptr noalias, ptr noalias readonly, i32, i1) |
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.