From 3cef3cf02f09e397c471cf008060c89b34951959 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 11 Jan 2022 12:08:44 +0100 Subject: [PATCH] [DSE] Check for noalias calls rather than alloc functions For these "visible on unwind/ret" checks we only care about the fact that no other code has access to the pointer (unless it escapes). A noalias call is sufficient for this, it does not have to be a known allocation function. This is basically the same change as D116728, but for DSE rather than LICM. --- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 4 ++-- llvm/test/Transforms/DeadStoreElimination/simple.ll | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index a8f7c4f..bb2092f 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -961,7 +961,7 @@ struct DSEState { I.first->second = false; } else { auto *Inst = dyn_cast(V); - if (Inst && isAllocLikeFn(Inst, &TLI)) + if (Inst && isNoAliasCall(Inst)) I.first->second = !PointerMayBeCaptured(V, true, false); } } @@ -974,7 +974,7 @@ struct DSEState { auto I = InvisibleToCallerBeforeRet.insert({V, false}); if (I.second) { auto *Inst = dyn_cast(V); - if (Inst && isAllocLikeFn(Inst, &TLI)) + if (Inst && isNoAliasCall(Inst)) // NOTE: This could be made more precise by PointerMayBeCapturedBefore // with the killing MemoryDef. But we refrain from doing so for now to // limit compile-time and this does not cause any changes to the number diff --git a/llvm/test/Transforms/DeadStoreElimination/simple.ll b/llvm/test/Transforms/DeadStoreElimination/simple.ll index 8d24715..14716ee 100644 --- a/llvm/test/Transforms/DeadStoreElimination/simple.ll +++ b/llvm/test/Transforms/DeadStoreElimination/simple.ll @@ -229,9 +229,6 @@ define i32* @test_custom_malloc_no_escape_before_return() { ; CHECK-LABEL: @test_custom_malloc_no_escape_before_return( ; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @custom_malloc(i32 4) ; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32* -; CHECK-NEXT: [[DEAD:%.*]] = load i32, i32* [[P]], align 4 -; CHECK-NEXT: [[DEAD2:%.*]] = add i32 [[DEAD]], 1 -; CHECK-NEXT: store i32 [[DEAD2]], i32* [[P]], align 4 ; CHECK-NEXT: call void @may_unwind() ; CHECK-NEXT: store i32 0, i32* [[P]], align 4 ; CHECK-NEXT: ret i32* [[P]] @@ -313,7 +310,6 @@ define void @malloc_no_escape() { define void @custom_malloc_no_escape() { ; CHECK-LABEL: @custom_malloc_no_escape( ; CHECK-NEXT: [[M:%.*]] = call i8* @custom_malloc(i32 24) -; CHECK-NEXT: store i8 0, i8* [[M]], align 1 ; CHECK-NEXT: ret void ; %m = call i8* @custom_malloc(i32 24) -- 2.7.4