2015-05-21 09:43:39 +08:00
|
|
|
; RUN: opt -basicaa -memcpyopt -S %s | FileCheck %s
|
2015-04-18 06:20:57 +08:00
|
|
|
|
|
|
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i64 %src_size
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i64 %dst_size, %src_size
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i64 %dst_size, %src_size
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i64 0, i64 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[DST]], i8 %c, i64 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
; CHECK-NEXT: ret void
|
2015-04-19 01:57:41 +08:00
|
|
|
define void @test(i8* %src, i64 %src_size, i8* %dst, i64 %dst_size, i8 %c) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 %c, i64 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-19 01:57:41 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test_different_types_i32_i64
|
|
|
|
; CHECK-DAG: [[DSTSIZE:%[0-9]+]] = zext i32 %dst_size to i64
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i64 %src_size
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i64 [[DSTSIZE]], %src_size
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i64 [[DSTSIZE]], %src_size
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i64 0, i64 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[DST]], i8 %c, i64 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-19 01:57:41 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_different_types_i32_i64(i8* %dst, i8* %src, i32 %dst_size, i64 %src_size, i8 %c) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i32(i8* %dst, i8 %c, i32 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-04-19 07:06:04 +08:00
|
|
|
; CHECK-LABEL: define void @test_different_types_i128_i32
|
|
|
|
; CHECK-DAG: [[SRCSIZE:%[0-9]+]] = zext i32 %src_size to i128
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i128 [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i128 %dst_size, [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i128 %dst_size, [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i128 0, i128 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i128(i8* [[DST]], i8 %c, i128 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %src_size, i32 1, i1 false)
|
2015-04-19 07:06:04 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_different_types_i128_i32(i8* %dst, i8* %src, i128 %dst_size, i32 %src_size, i8 %c) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i128(i8* %dst, i8 %c, i128 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %src_size, i32 1, i1 false)
|
2015-04-19 07:06:04 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test_different_types_i32_i128
|
|
|
|
; CHECK-DAG: [[DSTSIZE:%[0-9]+]] = zext i32 %dst_size to i128
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i128 %src_size
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i128 [[DSTSIZE]], %src_size
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i128 [[DSTSIZE]], %src_size
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i128 0, i128 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i128(i8* [[DST]], i8 %c, i128 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i128(i8* %dst, i8* %src, i128 %src_size, i32 1, i1 false)
|
2015-04-19 07:06:04 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_different_types_i32_i128(i8* %dst, i8* %src, i32 %dst_size, i128 %src_size, i8 %c) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i32(i8* %dst, i8 %c, i32 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i128(i8* %dst, i8* %src, i128 %src_size, i32 1, i1 false)
|
2015-04-19 07:06:04 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-04-19 01:57:41 +08:00
|
|
|
; CHECK-LABEL: define void @test_different_types_i64_i32
|
|
|
|
; CHECK-DAG: [[SRCSIZE:%[0-9]+]] = zext i32 %src_size to i64
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i64 [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i64 %dst_size, [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i64 %dst_size, [[SRCSIZE]]
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i64 0, i64 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[DST]], i8 %c, i64 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %src_size, i32 1, i1 false)
|
2015-04-19 01:57:41 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_different_types_i64_i32(i8* %dst, i8* %src, i64 %dst_size, i32 %src_size, i8 %c) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 %c, i64 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %src_size, i32 1, i1 false)
|
2015-04-19 01:57:41 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-04-18 06:20:57 +08:00
|
|
|
; CHECK-LABEL: define void @test_align_same
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 {{.*}}, i32 8, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
define void @test_align_same(i8* %src, i8* %dst, i64 %dst_size) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %dst_size, i32 8, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 80, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test_align_min
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 {{.*}}, i32 4, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
define void @test_align_min(i8* %src, i8* %dst, i64 %dst_size) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %dst_size, i32 8, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 36, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test_align_memcpy
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 {{.*}}, i32 8, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
define void @test_align_memcpy(i8* %src, i8* %dst, i64 %dst_size) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 80, i32 8, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
[MemCpyOpt] Use the raw i8* dest when optimizing memset+memcpy.
MemIntrinsic::getDest() looks through pointer casts, and using it
directly when building the new GEP+memset results in stuff like:
%0 = getelementptr i64* %p, i32 16
%1 = bitcast i64* %0 to i8*
call ..memset(i8* %1, ...)
instead of the correct:
%0 = bitcast i64* %p to i8*
%1 = getelementptr i8* %0, i32 16
call ..memset(i8* %1, ...)
Instead, use getRawDest, which just gives you the i8* value.
While there, use the memcpy's dest, as it's live anyway.
In most cases, when the optimization triggers, the memset and memcpy
sizes are the same, so the built memset is 0-sized and eliminated.
The problem occurs when they're different.
Fixes a regression caused by r235232: PR23300.
llvm-svn: 235419
2015-04-22 05:28:33 +08:00
|
|
|
; CHECK-LABEL: define void @test_non_i8_dst_type
|
|
|
|
; CHECK-NEXT: %dst = bitcast i64* %dst_pi64 to i8*
|
|
|
|
; CHECK-DAG: [[DST:%[0-9]+]] = getelementptr i8, i8* %dst, i64 %src_size
|
|
|
|
; CHECK-DAG: [[ULE:%[0-9]+]] = icmp ule i64 %dst_size, %src_size
|
|
|
|
; CHECK-DAG: [[SIZEDIFF:%[0-9]+]] = sub i64 %dst_size, %src_size
|
|
|
|
; CHECK-DAG: [[SIZE:%[0-9]+]] = select i1 [[ULE]], i64 0, i64 [[SIZEDIFF]]
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[DST]], i8 %c, i64 [[SIZE]], i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
[MemCpyOpt] Use the raw i8* dest when optimizing memset+memcpy.
MemIntrinsic::getDest() looks through pointer casts, and using it
directly when building the new GEP+memset results in stuff like:
%0 = getelementptr i64* %p, i32 16
%1 = bitcast i64* %0 to i8*
call ..memset(i8* %1, ...)
instead of the correct:
%0 = bitcast i64* %p to i8*
%1 = getelementptr i8* %0, i32 16
call ..memset(i8* %1, ...)
Instead, use getRawDest, which just gives you the i8* value.
While there, use the memcpy's dest, as it's live anyway.
In most cases, when the optimization triggers, the memset and memcpy
sizes are the same, so the built memset is 0-sized and eliminated.
The problem occurs when they're different.
Fixes a regression caused by r235232: PR23300.
llvm-svn: 235419
2015-04-22 05:28:33 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_non_i8_dst_type(i8* %src, i64 %src_size, i64* %dst_pi64, i64 %dst_size, i8 %c) {
|
|
|
|
%dst = bitcast i64* %dst_pi64 to i8*
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 %c, i64 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %src_size, i32 1, i1 false)
|
[MemCpyOpt] Use the raw i8* dest when optimizing memset+memcpy.
MemIntrinsic::getDest() looks through pointer casts, and using it
directly when building the new GEP+memset results in stuff like:
%0 = getelementptr i64* %p, i32 16
%1 = bitcast i64* %0 to i8*
call ..memset(i8* %1, ...)
instead of the correct:
%0 = bitcast i64* %p to i8*
%1 = getelementptr i8* %0, i32 16
call ..memset(i8* %1, ...)
Instead, use getRawDest, which just gives you the i8* value.
While there, use the memcpy's dest, as it's live anyway.
In most cases, when the optimization triggers, the memset and memcpy
sizes are the same, so the built memset is 0-sized and eliminated.
The problem occurs when they're different.
Fixes a regression caused by r235232: PR23300.
llvm-svn: 235419
2015-04-22 05:28:33 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-04-18 06:20:57 +08:00
|
|
|
; CHECK-LABEL: define void @test_different_dst
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %dst_size, i32 1, i1 false)
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_different_dst(i8* %dst2, i8* %src, i64 %src_size, i8* %dst, i64 %dst_size) {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %dst_size, i32 1, i1 false)
|
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst2, i8* %src, i64 %src_size, i32 1, i1 false)
|
2015-04-18 06:20:57 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-05-12 07:09:46 +08:00
|
|
|
; Make sure we also take into account dependencies on the destination.
|
|
|
|
|
|
|
|
; CHECK-LABEL: define i8 @test_intermediate_read
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %a, i8 0, i64 64, i32 1, i1 false)
|
2015-05-12 07:09:46 +08:00
|
|
|
; CHECK-NEXT: %r = load i8, i8* %a
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 24, i32 1, i1 false)
|
2015-05-12 07:09:46 +08:00
|
|
|
; CHECK-NEXT: ret i8 %r
|
|
|
|
define i8 @test_intermediate_read(i8* %a, i8* %b) #0 {
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %a, i8 0, i64 64, i32 1, i1 false)
|
2015-05-12 07:09:46 +08:00
|
|
|
%r = load i8, i8* %a
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 24, i32 1, i1 false)
|
2015-05-12 07:09:46 +08:00
|
|
|
ret i8 %r
|
|
|
|
}
|
|
|
|
|
2015-05-21 09:43:39 +08:00
|
|
|
%struct = type { [8 x i8], [8 x i8] }
|
|
|
|
|
|
|
|
; CHECK-LABEL: define void @test_intermediate_write
|
|
|
|
; CHECK-NEXT: %a = alloca %struct
|
|
|
|
; CHECK-NEXT: %a0 = getelementptr %struct, %struct* %a, i32 0, i32 0, i32 0
|
|
|
|
; CHECK-NEXT: %a1 = getelementptr %struct, %struct* %a, i32 0, i32 1, i32 0
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %a0, i8 0, i64 16, i32 1, i1 false)
|
2015-05-21 09:43:39 +08:00
|
|
|
; CHECK-NEXT: store i8 1, i8* %a1
|
2015-11-19 13:56:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a0, i8* %b, i64 8, i32 1, i1 false)
|
2015-05-21 09:43:39 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
define void @test_intermediate_write(i8* %b) #0 {
|
|
|
|
%a = alloca %struct
|
|
|
|
%a0 = getelementptr %struct, %struct* %a, i32 0, i32 0, i32 0
|
|
|
|
%a1 = getelementptr %struct, %struct* %a, i32 0, i32 1, i32 0
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memset.p0i8.i64(i8* %a0, i8 0, i64 16, i32 1, i1 false)
|
2015-05-21 09:43:39 +08:00
|
|
|
store i8 1, i8* %a1
|
2015-11-19 13:56:52 +08:00
|
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a0, i8* %b, i64 8, i32 1, i1 false)
|
2015-05-21 09:43:39 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:56:52 +08:00
|
|
|
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1)
|
|
|
|
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
|
|
|
|
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1)
|
|
|
|
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1)
|
|
|
|
declare void @llvm.memset.p0i8.i128(i8* nocapture, i8, i128, i32, i1)
|
|
|
|
declare void @llvm.memcpy.p0i8.p0i8.i128(i8* nocapture, i8* nocapture readonly, i128, i32, i1)
|