Skip to content

Commit 3cef3cf

Browse files
committed
[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.
1 parent ec01668 commit 3cef3cf

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ struct DSEState {
961961
I.first->second = false;
962962
} else {
963963
auto *Inst = dyn_cast<Instruction>(V);
964-
if (Inst && isAllocLikeFn(Inst, &TLI))
964+
if (Inst && isNoAliasCall(Inst))
965965
I.first->second = !PointerMayBeCaptured(V, true, false);
966966
}
967967
}
@@ -974,7 +974,7 @@ struct DSEState {
974974
auto I = InvisibleToCallerBeforeRet.insert({V, false});
975975
if (I.second) {
976976
auto *Inst = dyn_cast<Instruction>(V);
977-
if (Inst && isAllocLikeFn(Inst, &TLI))
977+
if (Inst && isNoAliasCall(Inst))
978978
// NOTE: This could be made more precise by PointerMayBeCapturedBefore
979979
// with the killing MemoryDef. But we refrain from doing so for now to
980980
// limit compile-time and this does not cause any changes to the number

llvm/test/Transforms/DeadStoreElimination/simple.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ define i32* @test_custom_malloc_no_escape_before_return() {
229229
; CHECK-LABEL: @test_custom_malloc_no_escape_before_return(
230230
; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @custom_malloc(i32 4)
231231
; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
232-
; CHECK-NEXT: [[DEAD:%.*]] = load i32, i32* [[P]], align 4
233-
; CHECK-NEXT: [[DEAD2:%.*]] = add i32 [[DEAD]], 1
234-
; CHECK-NEXT: store i32 [[DEAD2]], i32* [[P]], align 4
235232
; CHECK-NEXT: call void @may_unwind()
236233
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
237234
; CHECK-NEXT: ret i32* [[P]]
@@ -313,7 +310,6 @@ define void @malloc_no_escape() {
313310
define void @custom_malloc_no_escape() {
314311
; CHECK-LABEL: @custom_malloc_no_escape(
315312
; CHECK-NEXT: [[M:%.*]] = call i8* @custom_malloc(i32 24)
316-
; CHECK-NEXT: store i8 0, i8* [[M]], align 1
317313
; CHECK-NEXT: ret void
318314
;
319315
%m = call i8* @custom_malloc(i32 24)

0 commit comments

Comments
 (0)