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; 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 + +@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 +}