Skip to content

Commit

Permalink
[DSE] Check for noalias calls rather than alloc functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jan 11, 2022
1 parent ec01668 commit 3cef3cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Expand Up @@ -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);
}
}
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions llvm/test/Transforms/DeadStoreElimination/simple.ll
Expand Up @@ -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]]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3cef3cf

Please sign in to comment.