diff options
author | Nikita Popov <npopov@redhat.com> | 2022-01-11 12:08:44 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-01-11 12:22:16 +0100 |
commit | 3cef3cf02f09e397c471cf008060c89b34951959 (patch) | |
tree | 0dc878c7ce347820f77e0f69bfc9e5e176d7be3f | |
parent | ec016681d33f6f448207ca6b588783697326cb00 (diff) | |
download | llvm-3cef3cf02f09e397c471cf008060c89b34951959.tar.gz |
[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.
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 4 | ||||
-rw-r--r-- | 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 a8f7c4f95b01..bb2092f82b9c 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<Instruction>(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<Instruction>(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 8d24715ec39c..14716ee9b0e6 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) |