[PATCH] D108123: [MemoryBuiltins] Mark user defined delete as nobuiltin

guopeilin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 17 20:47:05 PDT 2021


guopeilin updated this revision to Diff 367103.
guopeilin retitled this revision from "[Local] Move isFreeCall() before willReturn()" to "[MemoryBuiltins] Mark user defined delete as nobuiltin".
guopeilin edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108123/new/

https://reviews.llvm.org/D108123

Files:
  llvm/lib/Analysis/MemoryBuiltins.cpp
  llvm/test/Transforms/InstCombine/overload-delete-empty.ll


Index: llvm/test/Transforms/InstCombine/overload-delete-empty.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/overload-delete-empty.ll
@@ -0,0 +1,51 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S -o - | FileCheck %s
+
+ at a = dso_local local_unnamed_addr global i32 0, align 4
+
+; Function Attrs: mustprogress nobuiltin noinline nounwind uwtable
+define dso_local void @_ZdlPv(i8* %p) local_unnamed_addr {
+entry:
+  store i32 1, i32* @a, align 4
+  ret void
+}
+
+; Function Attrs: mustprogress uwtable
+define dso_local i32 @_Z4testv() local_unnamed_addr {
+; CHECK-LABEL: @_Z4testv(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store i32 2, i32* @a, align 4
+; CHECK-NEXT:    br label [[DELETE_NOTNULL:%.*]]
+; CHECK:       delete.notnull:
+; CHECK-NEXT:    call void @_ZdlPv(i8* undef)
+; CHECK-NEXT:    br label [[DELETE_END:%.*]]
+; CHECK:       delete.end:
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* @a, align 4
+; CHECK-NEXT:    ret i32 [[TMP0]]
+;
+entry:
+  %call = call noalias nonnull i8* @_Znwm(i64 4)
+  %0 = bitcast i8* %call to i32*
+  store i32 2, i32* %0, align 4
+  store i32 2, i32* @a, align 4
+  br label %delete.notnull
+
+delete.notnull:                                   ; preds = %entry
+  call void @_ZdlPv(i8* undef)
+  br label %delete.end
+
+delete.end:                                       ; preds = %delete.notnull
+  %1 = load i32, i32* @a, align 4
+  ret i32 %1
+}
+
+; Function Attrs: nobuiltin allocsize(0)
+declare dso_local nonnull i8* @_Znwm(i64) local_unnamed_addr
+
+; Function Attrs: mustprogress norecurse uwtable
+define dso_local i32 @main() local_unnamed_addr {
+entry:
+  %call = call i32 @_Z4testv()
+  store i32 %call, i32* @a, align 4
+  ret i32 1
+}
Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -488,6 +488,13 @@
   bool IsNoBuiltinCall;
   const Function *Callee =
       getCalledFunction(I, /*LookThroughBitCast=*/false, IsNoBuiltinCall);
+  
+  // If the function has an exact definition (the function
+  // is manually overloaded), the call site should be NoBuiltin.
+  if (Callee != nullptr && Callee->hasExactDefinition()) {
+    IsNoBuiltinCall = true;
+  }
+
   if (Callee == nullptr || IsNoBuiltinCall)
     return nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108123.367103.patch
Type: text/x-patch
Size: 2478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210818/6a4a9474/attachment.bin>


More information about the llvm-commits mailing list