[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)

Haopeng Liu via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 22:35:12 PDT 2024


================
@@ -1602,7 +1731,17 @@ struct DSEState {
 
       // Uses which may read the original MemoryDef mean we cannot eliminate the
       // original MD. Stop walk.
-      if (isReadClobber(MaybeDeadLoc, UseInst)) {
+      // If KillingDef is a CallInst with "initializes" attribute, the reads in
+      // Callee would be dominated by initializations, so this should be safe.
+      bool IsKillingDefFromInitAttr = false;
+      if (IsInitializesAttrMemLoc) {
+        if (KillingI == UseInst &&
+            KillingUndObj == getUnderlyingObject(MaybeDeadLoc.Ptr)) {
----------------
haopliu wrote:

Nice catch! Added a new unit test, `p1_write_then_read_caller_with_clobber`, to test this inner condition.

https://github.com/llvm/llvm-project/pull/107282


More information about the llvm-commits mailing list