2019-08-05 17:58:32 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
|
|
|
|
|
|
|
define i8* @memcpy_nonconst_n(i8* %d, i8* nocapture readonly %s, i64 %n) {
|
|
|
|
; CHECK-LABEL: @memcpy_nonconst_n(
|
[InstCombine] mempcpy(d,s,n) to memcpy(d,s,n) + n
Summary:
Back-end currently expands mempcpy, but middle-end should work with memcpy instead of mempcpy to enable more memcpy-optimization.
GCC backend emits mempcpy, so LLVM backend could form it too, if we know mempcpy libcall is better than memcpy + n.
https://godbolt.org/z/dOCG96
Reviewers: efriedma, spatel, craig.topper, RKSimon, jdoerfert
Reviewed By: efriedma
Subscribers: hjl.tools, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65737
llvm-svn: 370593
2019-09-01 02:19:05 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[D:%.*]], i8* align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[D]], i64 [[N]]
|
|
|
|
; CHECK-NEXT: ret i8* [[TMP1]]
|
2019-08-05 17:58:32 +08:00
|
|
|
;
|
|
|
|
%r = tail call i8* @mempcpy(i8* %d, i8* %s, i64 %n)
|
|
|
|
ret i8* %r
|
|
|
|
}
|
|
|
|
|
[InstCombine] mempcpy(d,s,n) to memcpy(d,s,n) + n
Summary:
Back-end currently expands mempcpy, but middle-end should work with memcpy instead of mempcpy to enable more memcpy-optimization.
GCC backend emits mempcpy, so LLVM backend could form it too, if we know mempcpy libcall is better than memcpy + n.
https://godbolt.org/z/dOCG96
Reviewers: efriedma, spatel, craig.topper, RKSimon, jdoerfert
Reviewed By: efriedma
Subscribers: hjl.tools, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65737
llvm-svn: 370593
2019-09-01 02:19:05 +08:00
|
|
|
define i8* @memcpy_nonconst_n_copy_attrs(i8* %d, i8* nocapture readonly %s, i64 %n) {
|
|
|
|
; CHECK-LABEL: @memcpy_nonconst_n_copy_attrs(
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(16) [[D:%.*]], i8* align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[D]], i64 [[N]]
|
|
|
|
; CHECK-NEXT: ret i8* [[TMP1]]
|
|
|
|
;
|
|
|
|
%r = tail call i8* @mempcpy(i8* dereferenceable(16) %d, i8* %s, i64 %n)
|
|
|
|
ret i8* %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @memcpy_nonconst_n_unused_retval(i8* %d, i8* nocapture readonly %s, i64 %n) {
|
|
|
|
; CHECK-LABEL: @memcpy_nonconst_n_unused_retval(
|
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[D:%.*]], i8* align 1 [[S:%.*]], i64 [[N:%.*]], i1 false)
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
|
|
|
call i8* @mempcpy(i8* %d, i8* %s, i64 %n)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2019-08-05 17:58:32 +08:00
|
|
|
define i8* @memcpy_small_const_n(i8* %d, i8* nocapture readonly %s) {
|
|
|
|
; CHECK-LABEL: @memcpy_small_const_n(
|
[InstCombine] mempcpy(d,s,n) to memcpy(d,s,n) + n
Summary:
Back-end currently expands mempcpy, but middle-end should work with memcpy instead of mempcpy to enable more memcpy-optimization.
GCC backend emits mempcpy, so LLVM backend could form it too, if we know mempcpy libcall is better than memcpy + n.
https://godbolt.org/z/dOCG96
Reviewers: efriedma, spatel, craig.topper, RKSimon, jdoerfert
Reviewed By: efriedma
Subscribers: hjl.tools, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65737
llvm-svn: 370593
2019-09-01 02:19:05 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[S:%.*]] to i64*
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[D:%.*]] to i64*
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = load i64, i64* [[TMP1]], align 1
|
|
|
|
; CHECK-NEXT: store i64 [[TMP3]], i64* [[TMP2]], align 1
|
|
|
|
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i8, i8* [[D]], i64 8
|
|
|
|
; CHECK-NEXT: ret i8* [[TMP4]]
|
2019-08-05 17:58:32 +08:00
|
|
|
;
|
|
|
|
%r = tail call i8* @mempcpy(i8* %d, i8* %s, i64 8)
|
|
|
|
ret i8* %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define i8* @memcpy_big_const_n(i8* %d, i8* nocapture readonly %s) {
|
|
|
|
; CHECK-LABEL: @memcpy_big_const_n(
|
[SimplifyLibCalls] Mark known arguments with nonnull
Reviewers: efriedma, jdoerfert
Reviewed By: jdoerfert
Subscribers: ychen, rsmith, joerg, aaron.ballman, lebedev.ri, uenoku, jdoerfert, hfinkel, javed.absar, spatel, dmgreen, llvm-commits
Differential Revision: https://reviews.llvm.org/D53342
llvm-svn: 372091
2019-09-17 17:32:52 +08:00
|
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 dereferenceable(1024) [[D:%.*]], i8* nonnull align 1 dereferenceable(1024) [[S:%.*]], i64 1024, i1 false)
|
[InstCombine] mempcpy(d,s,n) to memcpy(d,s,n) + n
Summary:
Back-end currently expands mempcpy, but middle-end should work with memcpy instead of mempcpy to enable more memcpy-optimization.
GCC backend emits mempcpy, so LLVM backend could form it too, if we know mempcpy libcall is better than memcpy + n.
https://godbolt.org/z/dOCG96
Reviewers: efriedma, spatel, craig.topper, RKSimon, jdoerfert
Reviewed By: efriedma
Subscribers: hjl.tools, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65737
llvm-svn: 370593
2019-09-01 02:19:05 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[D]], i64 1024
|
|
|
|
; CHECK-NEXT: ret i8* [[TMP1]]
|
2019-08-05 17:58:32 +08:00
|
|
|
;
|
|
|
|
%r = tail call i8* @mempcpy(i8* %d, i8* %s, i64 1024)
|
|
|
|
ret i8* %r
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i8* @mempcpy(i8*, i8* nocapture readonly, i64)
|