diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -144,9 +144,7 @@ // FIXME: certain users need more information. E.g., SimplifyLibCalls needs to // know which functions are nounwind, noalias, nocapture parameters, etc. static const std::pair AllocationFnData[] = { - {LibFunc_malloc, {MallocLike, 1, 0, -1, -1, MallocFamily::Malloc}}, {LibFunc_vec_malloc, {MallocLike, 1, 0, -1, -1, MallocFamily::VecMalloc}}, - {LibFunc_valloc, {MallocLike, 1, 0, -1, -1, MallocFamily::Malloc}}, {LibFunc_Znwj, {OpNewLike, 1, 0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int) {LibFunc_ZnwjRKSt9nothrow_t, {MallocLike, 2, 0, -1, -1, MallocFamily::CPPNew}}, // new(unsigned int, nothrow) {LibFunc_ZnwjSt11align_val_t, {OpNewLike, 2, 0, -1, 1, MallocFamily::CPPNewAligned}}, // new(unsigned int, align_val_t) @@ -171,13 +169,9 @@ {LibFunc_msvc_new_array_int_nothrow, {MallocLike, 2, 0, -1, -1, MallocFamily::MSVCArrayNew}}, // new[](unsigned int, nothrow) {LibFunc_msvc_new_array_longlong, {OpNewLike, 1, 0, -1, -1, MallocFamily::MSVCArrayNew}}, // new[](unsigned long long) {LibFunc_msvc_new_array_longlong_nothrow, {MallocLike, 2, 0, -1, -1, MallocFamily::MSVCArrayNew}}, // new[](unsigned long long, nothrow) - {LibFunc_aligned_alloc, {AlignedAllocLike, 2, 1, -1, 0, MallocFamily::Malloc}}, {LibFunc_memalign, {AlignedAllocLike, 2, 1, -1, 0, MallocFamily::Malloc}}, - {LibFunc_calloc, {CallocLike, 2, 0, 1, -1, MallocFamily::Malloc}}, {LibFunc_vec_calloc, {CallocLike, 2, 0, 1, -1, MallocFamily::VecMalloc}}, - {LibFunc_realloc, {ReallocLike, 2, 1, -1, -1, MallocFamily::Malloc}}, {LibFunc_vec_realloc, {ReallocLike, 2, 1, -1, -1, MallocFamily::VecMalloc}}, - {LibFunc_reallocf, {ReallocLike, 2, 1, -1, -1, MallocFamily::Malloc}}, {LibFunc_strdup, {StrDupLike, 1, -1, -1, -1, MallocFamily::Malloc}}, {LibFunc_dunder_strdup, {StrDupLike, 1, -1, -1, -1, MallocFamily::Malloc}}, {LibFunc_strndup, {StrDupLike, 2, 1, -1, -1, MallocFamily::Malloc}}, @@ -509,7 +503,6 @@ // clang-format off static const std::pair FreeFnData[] = { - {LibFunc_free, {1, MallocFamily::Malloc}}, {LibFunc_vec_free, {1, MallocFamily::VecMalloc}}, {LibFunc_ZdlPv, {1, MallocFamily::CPPNew}}, // operator delete(void*) {LibFunc_ZdaPv, {1, MallocFamily::CPPNewArray}}, // operator delete[](void*) diff --git a/llvm/test/Transforms/Attributor/heap_to_stack.ll b/llvm/test/Transforms/Attributor/heap_to_stack.ll --- a/llvm/test/Transforms/Attributor/heap_to_stack.ll +++ b/llvm/test/Transforms/Attributor/heap_to_stack.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals -; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM +; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=8 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=8 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM ; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM @@ -34,14 +34,14 @@ ; IS________OPM-LABEL: define {{[^@]+}}@h2s_value_simplify_interaction ; IS________OPM-SAME: (i1 [[C:%.*]], i8* nocapture nofree readnone [[A:%.*]]) { ; IS________OPM-NEXT: entry: -; IS________OPM-NEXT: [[M:%.*]] = tail call noalias align 16 i8* @malloc(i64 noundef 4) +; IS________OPM-NEXT: [[M_H2S:%.*]] = alloca i8, i64 4, align 16 ; IS________OPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] ; IS________OPM: t: ; IS________OPM-NEXT: br i1 false, label [[DEAD:%.*]], label [[F2:%.*]] ; IS________OPM: f: ; IS________OPM-NEXT: br label [[J:%.*]] ; IS________OPM: f2: -; IS________OPM-NEXT: [[C1:%.*]] = bitcast i8* [[M]] to i32* +; IS________OPM-NEXT: [[C1:%.*]] = bitcast i8* [[M_H2S]] to i32* ; IS________OPM-NEXT: [[C2:%.*]] = bitcast i32* [[C1]] to i8* ; IS________OPM-NEXT: [[L:%.*]] = load i8, i8* [[C2]], align 16 ; IS________OPM-NEXT: call void @usei8(i8 [[L]]) @@ -195,7 +195,7 @@ ; ; IS________NPM-LABEL: define {{[^@]+}}@test3b ; IS________NPM-SAME: (i8* nocapture [[P:%.*]]) { -; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 128, align 32 +; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 128, align 1 ; IS________NPM-NEXT: tail call void @nofree_arg_only(i8* noalias nocapture nofree [[DOTH2S]], i8* nocapture [[P]]) ; IS________NPM-NEXT: ret void ; @@ -207,11 +207,16 @@ ; leave alone non-constant alignments. define void @test3c(i64 %alignment) { -; CHECK-LABEL: define {{[^@]+}}@test3c -; CHECK-SAME: (i64 [[ALIGNMENT:%.*]]) { -; CHECK-NEXT: [[TMP1:%.*]] = tail call noalias i8* @aligned_alloc(i64 [[ALIGNMENT]], i64 noundef 128) -; CHECK-NEXT: tail call void @free(i8* noalias nocapture [[TMP1]]) -; CHECK-NEXT: ret void +; IS________OPM-LABEL: define {{[^@]+}}@test3c +; IS________OPM-SAME: (i64 [[ALIGNMENT:%.*]]) { +; IS________OPM-NEXT: [[TMP1:%.*]] = tail call noalias i8* @aligned_alloc(i64 [[ALIGNMENT]], i64 noundef 128) +; IS________OPM-NEXT: tail call void @free(i8* noalias nocapture [[TMP1]]) +; IS________OPM-NEXT: ret void +; +; IS________NPM-LABEL: define {{[^@]+}}@test3c +; IS________NPM-SAME: (i64 [[ALIGNMENT:%.*]]) { +; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 128, align 1 +; IS________NPM-NEXT: ret void ; %1 = tail call noalias i8* @aligned_alloc(i64 %alignment, i64 128) tail call void @free(i8* %1) @@ -229,9 +234,8 @@ ; ; IS________NPM-LABEL: define {{[^@]+}}@test3d ; IS________NPM-SAME: (i8* nocapture [[P:%.*]]) { -; IS________NPM-NEXT: [[TMP1:%.*]] = tail call noalias i8* @aligned_alloc(i64 noundef 33, i64 noundef 128) -; IS________NPM-NEXT: tail call void @nofree_arg_only(i8* noalias nocapture nofree [[TMP1]], i8* nocapture [[P]]) -; IS________NPM-NEXT: tail call void @free(i8* noalias nocapture [[TMP1]]) +; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 128, align 1 +; IS________NPM-NEXT: tail call void @nofree_arg_only(i8* noalias nocapture nofree [[DOTH2S]], i8* nocapture [[P]]) ; IS________NPM-NEXT: ret void ; ; CHECK-SAME; (i8* nocapture [[P:%.*]]) { @@ -264,15 +268,10 @@ ; TEST 4 define void @test4() { -; IS________OPM-LABEL: define {{[^@]+}}@test4() { -; IS________OPM-NEXT: [[TMP1:%.*]] = tail call noalias i8* @malloc(i64 noundef 4) -; IS________OPM-NEXT: tail call void @nofree_func(i8* noalias nocapture nofree [[TMP1]]) -; IS________OPM-NEXT: ret void -; -; IS________NPM-LABEL: define {{[^@]+}}@test4() { -; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 1 -; IS________NPM-NEXT: tail call void @nofree_func(i8* noalias nocapture nofree [[DOTH2S]]) -; IS________NPM-NEXT: ret void +; CHECK-LABEL: define {{[^@]+}}@test4() { +; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 1 +; CHECK-NEXT: tail call void @nofree_func(i8* noalias nocapture nofree [[DOTH2S]]) +; CHECK-NEXT: ret void ; %1 = tail call noalias i8* @malloc(i64 4) tail call void @nofree_func(i8* %1) @@ -555,11 +554,10 @@ ; IS________OPM-NEXT: [[TMP14]] = add nsw i32 [[DOT1]], 1 ; IS________OPM-NEXT: br label [[TMP8]] ; IS________OPM: 15: -; IS________OPM-NEXT: [[TMP16:%.*]] = load i32, i32* [[TMP3]], align 4 -; IS________OPM-NEXT: [[TMP17:%.*]] = bitcast i32* [[TMP3]] to i8* -; IS________OPM-NEXT: call void @free(i8* nocapture noundef [[TMP17]]) -; IS________OPM-NEXT: [[TMP18:%.*]] = load i32, i32* [[TMP3]], align 4 -; IS________OPM-NEXT: ret i32 [[TMP18]] +; IS________OPM-NEXT: [[TMP16:%.*]] = bitcast i32* [[TMP3]] to i8* +; IS________OPM-NEXT: call void @free(i8* nocapture noundef [[TMP16]]) +; IS________OPM-NEXT: [[TMP17:%.*]] = load i32, i32* [[TMP3]], align 4 +; IS________OPM-NEXT: ret i32 [[TMP17]] ; ; IS________NPM-LABEL: define {{[^@]+}}@irreducible_cfg ; IS________NPM-SAME: (i32 [[TMP0:%.*]]) { @@ -630,43 +628,24 @@ define i32 @malloc_in_loop(i32 %0) { -; IS________OPM-LABEL: define {{[^@]+}}@malloc_in_loop -; IS________OPM-SAME: (i32 [[TMP0:%.*]]) { -; IS________OPM-NEXT: [[TMP2:%.*]] = alloca i32, align 4 -; IS________OPM-NEXT: [[TMP3:%.*]] = alloca i32*, align 8 -; IS________OPM-NEXT: store i32 [[TMP0]], i32* [[TMP2]], align 4 -; IS________OPM-NEXT: br label [[TMP4:%.*]] -; IS________OPM: 4: -; IS________OPM-NEXT: [[TMP5:%.*]] = load i32, i32* [[TMP2]], align 4 -; IS________OPM-NEXT: [[TMP6:%.*]] = add nsw i32 [[TMP5]], -1 -; IS________OPM-NEXT: store i32 [[TMP6]], i32* [[TMP2]], align 4 -; IS________OPM-NEXT: [[TMP7:%.*]] = icmp sgt i32 [[TMP6]], 0 -; IS________OPM-NEXT: br i1 [[TMP7]], label [[TMP8:%.*]], label [[TMP11:%.*]] -; IS________OPM: 8: -; IS________OPM-NEXT: [[TMP9:%.*]] = call noalias i8* @malloc(i64 noundef 4) -; IS________OPM-NEXT: [[TMP10:%.*]] = bitcast i8* [[TMP9]] to i32* -; IS________OPM-NEXT: br label [[TMP4]] -; IS________OPM: 11: -; IS________OPM-NEXT: ret i32 5 -; -; IS________NPM-LABEL: define {{[^@]+}}@malloc_in_loop -; IS________NPM-SAME: (i32 [[TMP0:%.*]]) { -; IS________NPM-NEXT: [[TMP2:%.*]] = alloca i32, align 4 -; IS________NPM-NEXT: [[TMP3:%.*]] = alloca i32*, align 8 -; IS________NPM-NEXT: store i32 [[TMP0]], i32* [[TMP2]], align 4 -; IS________NPM-NEXT: br label [[TMP4:%.*]] -; IS________NPM: 4: -; IS________NPM-NEXT: [[TMP5:%.*]] = load i32, i32* [[TMP2]], align 4 -; IS________NPM-NEXT: [[TMP6:%.*]] = add nsw i32 [[TMP5]], -1 -; IS________NPM-NEXT: store i32 [[TMP6]], i32* [[TMP2]], align 4 -; IS________NPM-NEXT: [[TMP7:%.*]] = icmp sgt i32 [[TMP6]], 0 -; IS________NPM-NEXT: br i1 [[TMP7]], label [[TMP8:%.*]], label [[TMP10:%.*]] -; IS________NPM: 8: -; IS________NPM-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 1 -; IS________NPM-NEXT: [[TMP9:%.*]] = bitcast i8* [[DOTH2S]] to i32* -; IS________NPM-NEXT: br label [[TMP4]] -; IS________NPM: 10: -; IS________NPM-NEXT: ret i32 5 +; CHECK-LABEL: define {{[^@]+}}@malloc_in_loop +; CHECK-SAME: (i32 [[TMP0:%.*]]) { +; CHECK-NEXT: [[TMP2:%.*]] = alloca i32, align 4 +; CHECK-NEXT: [[TMP3:%.*]] = alloca i32*, align 8 +; CHECK-NEXT: store i32 [[TMP0]], i32* [[TMP2]], align 4 +; CHECK-NEXT: br label [[TMP4:%.*]] +; CHECK: 4: +; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[TMP2]], align 4 +; CHECK-NEXT: [[TMP6:%.*]] = add nsw i32 [[TMP5]], -1 +; CHECK-NEXT: store i32 [[TMP6]], i32* [[TMP2]], align 4 +; CHECK-NEXT: [[TMP7:%.*]] = icmp sgt i32 [[TMP6]], 0 +; CHECK-NEXT: br i1 [[TMP7]], label [[TMP8:%.*]], label [[TMP10:%.*]] +; CHECK: 8: +; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 1 +; CHECK-NEXT: [[TMP9:%.*]] = bitcast i8* [[DOTH2S]] to i32* +; CHECK-NEXT: br label [[TMP4]] +; CHECK: 10: +; CHECK-NEXT: ret i32 5 ; %2 = alloca i32, align 4 %3 = alloca i32*, align 8