[llvm] eb2cad8 - [DSE] Make isRemovable() for calls more robust (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 17 11:53:44 PST 2021


Author: Nikita Popov
Date: 2021-12-17T20:52:34+01:00
New Revision: eb2cad8329b0526b6b4e9deaf7187530012a64f1

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

LOG: [DSE] Make isRemovable() for calls more robust (NFCI)

We can only drop calls if they have an analyzable write, the return
value is not used, they don't throw and they don't diverge. The last
two conditions were previously not checked, because all the libcalls
with analyzable writes already happened to satisfy those conditions
anyway. This may not be true for generalizations (with D115904 in mind).

No test changes because the necessary attributes are already inferred
for currently supported libcalls.

Differential Revision: https://reviews.llvm.org/D115962

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 757461bbd43b5..ee6c800e07a5c 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -206,9 +206,9 @@ static bool isRemovable(Instruction *I) {
     }
   }
 
-  // note: only get here for calls with analyzable writes - i.e. libcalls
+  // note: only get here for calls with analyzable writes.
   if (auto *CB = dyn_cast<CallBase>(I))
-    return CB->use_empty();
+    return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();
 
   return false;
 }


        


More information about the llvm-commits mailing list