llvm.org GIT mirror llvm / 863bc82
[InstCombine] Transform bcopy to memmove bcopy is still widely used mainly for network apps. Sadly, LLVM has no optimizations for bcopy, but there are some for memmove. Since bcopy == memmove, it is profitable to transform bcopy to memmove and use current optimizations for memmove for free here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373537 91177308-0d34-0410-b5e6-96231b3b80d8 David Bolvansky 1 year, 1 month ago
3 changed file(s) with 34 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
180180 Value *optimizeMemSet(CallInst *CI, IRBuilder<> &B);
181181 Value *optimizeRealloc(CallInst *CI, IRBuilder<> &B);
182182 Value *optimizeWcslen(CallInst *CI, IRBuilder<> &B);
183 Value *optimizeBCopy(CallInst *CI, IRBuilder<> &B);
183184 // Wrapper for all String/Memory Library Call Optimizations
184185 Value *optimizeStringMemoryLibCall(CallInst *CI, IRBuilder<> &B);
185186
27912791 return nullptr;
27922792 }
27932793
2794 Value *LibCallSimplifier::optimizeBCopy(CallInst *CI, IRBuilder<> &B) {
2795 // bcopy(src, dst, n) -> llvm.memmove(dst, src, n)
2796 return B.CreateMemMove(CI->getArgOperand(1), 1, CI->getArgOperand(0), 1,
2797 CI->getArgOperand(2));
2798 }
2799
27942800 bool LibCallSimplifier::hasFloatVersion(StringRef FuncName) {
27952801 LibFunc Func;
27962802 SmallString<20> FloatFuncName = FuncName;
28692875 return optimizeRealloc(CI, Builder);
28702876 case LibFunc_wcslen:
28712877 return optimizeWcslen(CI, Builder);
2878 case LibFunc_bcopy:
2879 return optimizeBCopy(CI, Builder);
28722880 default:
28732881 break;
28742882 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
3 declare void @bcopy(i8* nocapture readonly, i8* nocapture, i32)
4
5 define void @bcopy_memmove(i8* nocapture readonly %a, i8* nocapture %b) {
6 ; CHECK-LABEL: @bcopy_memmove(
7 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[A:%.*]] to i64*
8 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[B:%.*]] to i64*
9 ; CHECK-NEXT: [[TMP3:%.*]] = load i64, i64* [[TMP1]], align 1
10 ; CHECK-NEXT: store i64 [[TMP3]], i64* [[TMP2]], align 1
11 ; CHECK-NEXT: ret void
12 ;
13 tail call void @bcopy(i8* %a, i8* %b, i32 8)
14 ret void
15 }
16
17 define void @bcopy_memmove2(i8* nocapture readonly %a, i8* nocapture %b, i32 %len) {
18 ; CHECK-LABEL: @bcopy_memmove2(
19 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i32(i8* align 1 [[B:%.*]], i8* align 1 [[A:%.*]], i32 [[LEN:%.*]], i1 false)
20 ; CHECK-NEXT: ret void
21 ;
22 tail call void @bcopy(i8* %a, i8* %b, i32 %len)
23 ret void
24 }