diff options
| author | David Bolvansky <david.bolvansky@gmail.com> | 2019-09-17 10:25:38 +0000 | 
|---|---|---|
| committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-09-17 10:25:38 +0000 | 
| commit | ded48e93e600345159a826636c686ca481a3da69 (patch) | |
| tree | c0e061257c8f40714c38a3348234065cbaaa11d0 | |
| parent | 1a9195d817d35a0464394018a3575ccfe49eda80 (diff) | |
| download | bcm5719-llvm-ded48e93e600345159a826636c686ca481a3da69.tar.gz bcm5719-llvm-ded48e93e600345159a826636c686ca481a3da69.zip | |
[SLC] Preserve attrs for strncpy(x, "", y) -> memset(align 1 x, '\0', y)
llvm-svn: 372101
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/strncpy-1.ll | 10 | 
2 files changed, 14 insertions, 1 deletions
| diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 217f929e9ad..a5e31f21166 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -610,7 +610,10 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilder<> &B) {    if (SrcLen == 0) {      // strncpy(x, "", y) -> memset(align 1 x, '\0', y) -    B.CreateMemSet(Dst, B.getInt8('\0'), Size, 1); +    CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, 1); +    AttrBuilder ArgAttrs(CI->getAttributes().getParamAttributes(0)); +    NewCI->setAttributes(NewCI->getAttributes().addParamAttributes( +        CI->getContext(), 0, ArgAttrs));      return Dst;    } diff --git a/llvm/test/Transforms/InstCombine/strncpy-1.ll b/llvm/test/Transforms/InstCombine/strncpy-1.ll index 38e8cfedba2..969358eb4d7 100644 --- a/llvm/test/Transforms/InstCombine/strncpy-1.ll +++ b/llvm/test/Transforms/InstCombine/strncpy-1.ll @@ -134,6 +134,16 @@ define i8* @test2(i8* %dst) {    ret i8* %ret  } +define i8* @test3(i8* %dst, i32 %n) { +; CHECK-LABEL: @test3( +; CHECK-NEXT:    call void @llvm.memset.p0i8.i32(i8* noalias nonnull align 1 dereferenceable(5) [[DST:%.*]], i8 0, i32 5, i1 false) +; CHECK-NEXT:    ret i8* [[DST]] +; +  %src = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0 +  %ret = call i8* @strncpy(i8* noalias nonnull %dst, i8* nonnull %src, i32 5); +  ret i8* %ret +} +  ; Check cases that shouldn't be simplified.  define void @test_no_simplify1() { | 

