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

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


nikic created this revision.
nikic added reviewers: reames, fhahn, anna.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://reviews.llvm.org/D115904> in mind).

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


https://reviews.llvm.org/D115962

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


Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -206,9 +206,9 @@
     }
   }
 
-  // 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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115962.395188.patch
Type: text/x-patch
Size: 571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211217/bc156a18/attachment.bin>


More information about the llvm-commits mailing list