[llvm] 3cef3cf - [DSE] Check for noalias calls rather than alloc functions

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 11 03:22:24 PST 2022


Author: Nikita Popov
Date: 2022-01-11T12:22:16+01:00
New Revision: 3cef3cf02f09e397c471cf008060c89b34951959

URL: https://github.com/llvm/llvm-project/commit/3cef3cf02f09e397c471cf008060c89b34951959
DIFF: https://github.com/llvm/llvm-project/commit/3cef3cf02f09e397c471cf008060c89b34951959.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/test/Transforms/DeadStoreElimination/simple.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index a8f7c4f95b01c..bb2092f82b9c0 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 8d24715ec39ca..14716ee9b0e6a 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)


        


More information about the llvm-commits mailing list