[PATCH] D135075: [SimplifyLibCalls] Retain attributes added by Builder.CreateMem*

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 07:01:36 PDT 2022


arichardson created this revision.
arichardson added a reviewer: nikic.
Herald added subscribers: jrtc27, hiraditya.
Herald added a project: All.
arichardson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This currently does not make much of a difference (only one tests is
affected), but it is helpful e.g. for the out-of-tree CHERI target where
Builder.CreateMemCpy() can add attributes other than parameter alignment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135075

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/CodeGenPrepare/X86/memset_chk-simplify-nobuiltin.ll


Index: llvm/test/Transforms/CodeGenPrepare/X86/memset_chk-simplify-nobuiltin.ll
===================================================================
--- llvm/test/Transforms/CodeGenPrepare/X86/memset_chk-simplify-nobuiltin.ll
+++ llvm/test/Transforms/CodeGenPrepare/X86/memset_chk-simplify-nobuiltin.ll
@@ -11,7 +11,7 @@
 
 define void @test_nobuiltin(i8* %dst, i64 %len) {
 ; CHECK-LABEL: @test_nobuiltin(
-; CHECK-NEXT:    call void @llvm.memset.p0i8.i64(i8* [[DST:%.*]], i8 0, i64 [[LEN:%.*]], i1 false) #1
+; CHECK-NEXT:    call void @llvm.memset.p0i8.i64(i8* align 1 [[DST:%.*]], i8 0, i64 [[LEN:%.*]], i1 false)
 ; CHECK-NEXT:    ret void
 ;
   call i8* @__memset_chk(i8* %dst, i32 0, i64 %len, i64 -1) nobuiltin
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -288,7 +288,8 @@
 }
 
 static Value* mergeAttributesAndFlags(CallInst *NewCI, const CallInst &Old) {
-  NewCI->setAttributes(Old.getAttributes());
+  NewCI->setAttributes(AttributeList::get(
+      NewCI->getContext(), {NewCI->getAttributes(), Old.getAttributes()}));
   NewCI->removeRetAttrs(AttributeFuncs::typeIncompatible(NewCI->getType()));
   return copyFlags(Old, NewCI);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135075.464671.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221003/b4dcda25/attachment.bin>


More information about the llvm-commits mailing list