diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2015-11-18 22:17:24 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2015-11-18 22:17:24 +0000 |
| commit | 72bc23ef02bad3873d3572b2be529404a461d449 (patch) | |
| tree | f1a47c225592be2aa94fdcaf411d1d5f51a7c193 /llvm/test/Transforms/GlobalOpt | |
| parent | b035bd03e4db325de2380ea9263e10de5b9be3b6 (diff) | |
| download | bcm5719-llvm-72bc23ef02bad3873d3572b2be529404a461d449.tar.gz bcm5719-llvm-72bc23ef02bad3873d3572b2be529404a461d449.zip | |
Change memcpy/memset/memmove to have dest and source alignments.
Note, this was reviewed (and more details are in) http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html
These intrinsics currently have an explicit alignment argument which is
required to be a constant integer. It represents the alignment of the
source and dest, and so must be the minimum of those.
This change allows source and dest to each have their own alignments
by using the alignment attribute on their arguments. The alignment
argument itself is removed.
There are a few places in the code for which the code needs to be
checked by an expert as to whether using only src/dest alignment is
safe. For those places, they currently take the minimum of src/dest
alignments which matches the current behaviour.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 500, i32 8, i1 false)
will now read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %dest, i8* align 8 %src, i32 500, i1 false)
For out of tree owners, I was able to strip alignment from calls using sed by replacing:
(call.*llvm\.memset.*)i32\ [0-9]*\,\ i1 false\)
with:
$1i1 false)
and similarly for memmove and memcpy.
I then added back in alignment to test cases which needed it.
A similar commit will be made to clang which actually has many differences in alignment as now
IRBuilder can generate different source/dest alignments on calls.
In IRBuilder itself, a new argument was added. Instead of calling:
CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, /* isVolatile */ false)
you now call
CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, SrcAlign, /* isVolatile */ false)
There is a temporary class (IntegerAlignment) which takes the source alignment and rejects
implicit conversion from bool. This is to prevent isVolatile here from passing its default
parameter to the source alignment.
Note, changes in future can now be made to codegen. I didn't change anything here, but this
change should enable better memcpy code sequences.
Reviewed by Hal Finkel.
llvm-svn: 253511
Diffstat (limited to 'llvm/test/Transforms/GlobalOpt')
| -rw-r--r-- | llvm/test/Transforms/GlobalOpt/crash.ll | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/GlobalOpt/memcpy.ll | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/GlobalOpt/memset-null.ll | 6 | ||||
| -rw-r--r-- | llvm/test/Transforms/GlobalOpt/memset.ll | 14 |
4 files changed, 14 insertions, 14 deletions
diff --git a/llvm/test/Transforms/GlobalOpt/crash.ll b/llvm/test/Transforms/GlobalOpt/crash.ll index 8e39931c852..883b72efb40 100644 --- a/llvm/test/Transforms/GlobalOpt/crash.ll +++ b/llvm/test/Transforms/GlobalOpt/crash.ll @@ -60,10 +60,10 @@ entry: @data8 = internal global [8000 x i8] zeroinitializer, align 16 define void @memset_with_strange_user() ssp { - call void @llvm.memset.p0i8.i64(i8* getelementptr inbounds ([8000 x i8], [8000 x i8]* @data8, i64 0, i64 0), i8 undef, i64 ptrtoint (i8* getelementptr ([8000 x i8], [8000 x i8]* @data8, i64 1, i64 sub (i64 0, i64 ptrtoint ([8000 x i8]* @data8 to i64))) to i64), i32 16, i1 false) + call void @llvm.memset.p0i8.i64(i8* getelementptr inbounds ([8000 x i8], [8000 x i8]* @data8, i64 0, i64 0), i8 undef, i64 ptrtoint (i8* getelementptr ([8000 x i8], [8000 x i8]* @data8, i64 1, i64 sub (i64 0, i64 ptrtoint ([8000 x i8]* @data8 to i64))) to i64), i1 false) ret void } -declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind +declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind ; PR9856 diff --git a/llvm/test/Transforms/GlobalOpt/memcpy.ll b/llvm/test/Transforms/GlobalOpt/memcpy.ll index 437142e8c6e..b2b192bb1cd 100644 --- a/llvm/test/Transforms/GlobalOpt/memcpy.ll +++ b/llvm/test/Transforms/GlobalOpt/memcpy.ll @@ -6,8 +6,8 @@ define void @foo() { %Blah = alloca [58 x i8] %tmp.0 = getelementptr [58 x i8], [58 x i8]* %Blah, i32 0, i32 0 - call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp.0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @G1, i32 0, i32 0), i32 58, i32 1, i1 false) + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp.0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @G1, i32 0, i32 0), i32 58, i1 false) ret void } -declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind diff --git a/llvm/test/Transforms/GlobalOpt/memset-null.ll b/llvm/test/Transforms/GlobalOpt/memset-null.ll index 838ac0979e3..1a1f550851e 100644 --- a/llvm/test/Transforms/GlobalOpt/memset-null.ll +++ b/llvm/test/Transforms/GlobalOpt/memset-null.ll @@ -8,12 +8,12 @@ @a = global %struct.A zeroinitializer, align 4 @llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }, %0 { i32 65535, void ()* @_GLOBAL__I_b }] -declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind +declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind ; CHECK-NOT: GLOBAL__I_a define internal void @_GLOBAL__I_a() nounwind { entry: - tail call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.A* @a to i8*), i8 0, i64 400, i32 4, i1 false) nounwind + tail call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.A* @a to i8*), i8 0, i64 400, i1 false) nounwind ret void } @@ -24,6 +24,6 @@ entry: define internal void @_GLOBAL__I_b() nounwind { entry: %tmp.i.i.i = load i8*, i8** @y, align 8 - tail call void @llvm.memset.p0i8.i64(i8* %tmp.i.i.i, i8 0, i64 10, i32 1, i1 false) nounwind + tail call void @llvm.memset.p0i8.i64(i8* %tmp.i.i.i, i8 0, i64 10, i1 false) nounwind ret void } diff --git a/llvm/test/Transforms/GlobalOpt/memset.ll b/llvm/test/Transforms/GlobalOpt/memset.ll index 1dfdd642233..02bef2cfb63 100644 --- a/llvm/test/Transforms/GlobalOpt/memset.ll +++ b/llvm/test/Transforms/GlobalOpt/memset.ll @@ -10,8 +10,8 @@ define void @foo() { %Blah = alloca [58 x i8] %tmp3 = bitcast [58 x i8]* %Blah to i8* - call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast ([4 x i32]* @G1 to i8*), i8* %tmp3, i32 16, i32 1, i1 false) - call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @G0, i32 0, i32 0), i8 17, i32 58, i32 1, i1 false) + call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast ([4 x i32]* @G1 to i8*), i8* %tmp3, i32 16, i1 false) + call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @G0, i32 0, i32 0), i8 17, i32 58, i1 false) ret void } @@ -21,11 +21,11 @@ define void @foo() { define void @foo_as1() { %Blah = alloca [58 x i8] %tmp3 = bitcast [58 x i8]* %Blah to i8* - call void @llvm.memcpy.p0i8.p0i8.i32(i8* addrspacecast ([4 x i32] addrspace(1)* @G1_as1 to i8*), i8* %tmp3, i32 16, i32 1, i1 false) - call void @llvm.memset.p1i8.i32(i8 addrspace(1)* getelementptr inbounds ([58 x i8], [58 x i8] addrspace(1)* @G0_as1, i32 0, i32 0), i8 17, i32 58, i32 1, i1 false) + call void @llvm.memcpy.p0i8.p0i8.i32(i8* addrspacecast ([4 x i32] addrspace(1)* @G1_as1 to i8*), i8* %tmp3, i32 16, i1 false) + call void @llvm.memset.p1i8.i32(i8 addrspace(1)* getelementptr inbounds ([58 x i8], [58 x i8] addrspace(1)* @G0_as1, i32 0, i32 0), i8 17, i32 58, i1 false) ret void } -declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind -declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind -declare void @llvm.memset.p1i8.i32(i8 addrspace(1)* nocapture, i8, i32, i32, i1) nounwind
\ No newline at end of file +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind +declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind +declare void @llvm.memset.p1i8.i32(i8 addrspace(1)* nocapture, i8, i32, i1) nounwind
\ No newline at end of file |

