[PATCH] D100875: [SimplifyLibCalls] Don't change alignment when creating memset Fix for PR49984
Stefan Stipanovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 20 11:08:21 PDT 2021
sstefan1 created this revision.
sstefan1 added reviewers: jdoerfert, xbolva00.
Herald added a subscriber: hiraditya.
sstefan1 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100875
Files:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/strncpy-1.ll
Index: llvm/test/Transforms/InstCombine/strncpy-1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/strncpy-1.ll
+++ llvm/test/Transforms/InstCombine/strncpy-1.ll
@@ -144,6 +144,16 @@
ret i8* %ret
}
+define i8* @test4(i8* %dst, i32 %n) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* noalias noundef nonnull align 16 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* align(16) noalias nonnull %dst, i8* nonnull %src, i32 5);
+ ret i8* %ret
+}
+
; Check cases that shouldn't be simplified.
define void @test_no_simplify1() {
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -576,7 +576,9 @@
if (SrcLen == 0) {
// strncpy(x, "", y) -> memset(align 1 x, '\0', y)
- CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, Align(1));
+ Align MemSetAlign =
+ CI->getAttributes().getParamAttributes(0).getAlignment().valueOrOne();
+ CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, MemSetAlign);
AttrBuilder ArgAttrs(CI->getAttributes().getParamAttributes(0));
NewCI->setAttributes(NewCI->getAttributes().addParamAttributes(
CI->getContext(), 0, ArgAttrs));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100875.338935.patch
Type: text/x-patch
Size: 1530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210420/953a574c/attachment.bin>
More information about the llvm-commits
mailing list