[PATCH] D45344: [InstCombine] Fold malloc + memset to calloc even for llvm.memset
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 6 14:16:33 PDT 2018
xbolva00 updated this revision to Diff 141424.
xbolva00 added a comment.
Added test
https://reviews.llvm.org/D45344
Files:
lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/memset-1.ll
Index: test/Transforms/InstCombine/memset-1.ll
===================================================================
--- test/Transforms/InstCombine/memset-1.ll
+++ test/Transforms/InstCombine/memset-1.ll
@@ -102,6 +102,15 @@
ret i8* %memset
}
+define i8* @memset_intrinstic_unchanged(i8* %ptr) #0 {
+; CHECK-LABEL: @memset_intrinstic_unchanged(
+; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* align 1 [[PTR:%.*]], i8 0, i32 10, i1 false)
+; CHECK-NEXT: ret i8* [[PTR]]
+;
+ call void @llvm.memset.p0i8.i32(i8* %ptr, i8 0, i32 10, i32 1, i1 false)
+ ret i8* %ptr
+}
+
attributes #0 = { nounwind ssp uwtable }
attributes #1 = { nounwind }
attributes #2 = { nounwind readnone }
Index: lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -883,6 +883,9 @@
if (auto *Calloc = foldMallocMemset(CI, B, *TLI))
return Calloc;
+ if (CI->getCalledFunction()->isIntrinsic())
+ return nullptr;
+
// memset(p, v, n) -> llvm.memset(align 1 p, v, n)
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
@@ -2219,7 +2222,8 @@
return optimizeLog(CI, Builder);
case Intrinsic::sqrt:
return optimizeSqrt(CI, Builder);
- // TODO: Use foldMallocMemset() with memset intrinsic.
+ case Intrinsic::memset:
+ return optimizeMemSet(CI, Builder);
default:
return nullptr;
}
@@ -2509,4 +2513,4 @@
FortifiedLibCallSimplifier::FortifiedLibCallSimplifier(
const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize)
- : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
+ : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
\ No newline at end of file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45344.141424.patch
Type: text/x-patch
Size: 1873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/50572c5b/attachment.bin>
More information about the llvm-commits
mailing list