[llvm] af6b993 - [EarlyCSE][OpaquePtr] Check access type when performing DSE

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 12:03:46 PST 2022


Author: Arthur Eubanks
Date: 2022-02-17T11:58:53-08:00
New Revision: af6b9939aac065ce19bdaaf9fc54a8368367f33f

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

LOG: [EarlyCSE][OpaquePtr] Check access type when performing DSE

This will bail out on target specific intrinsics. If those are deemed
important enough for EarlyCSE to handle, we can augment MemIntrinsicInfo
with an access type for TargetTransformInfo::getTgtMemIntrinsic() to
handle.

Reviewed By: #opaque-pointers, nikic

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/EarlyCSE.cpp
    llvm/test/Transforms/EarlyCSE/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 59b934c16c8a0..091b7a51ccfc6 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -781,6 +781,21 @@ class EarlyCSE {
       return getLoadStorePointerOperand(Inst);
     }
 
+    Type *getValueType() const {
+      // TODO: handle target-specific intrinsics.
+      if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
+        switch (II->getIntrinsicID()) {
+        case Intrinsic::masked_load:
+          return II->getType();
+        case Intrinsic::masked_store:
+          return II->getArgOperand(0)->getType();
+        default:
+          return nullptr;
+        }
+      }
+      return getLoadStoreType(Inst);
+    }
+
     bool mayReadFromMemory() const {
       if (IntrID != 0)
         return Info.ReadMem;
@@ -1162,6 +1177,9 @@ bool EarlyCSE::overridingStores(const ParseMemoryInst &Earlier,
          "Violated invariant");
   if (Earlier.getPointerOperand() != Later.getPointerOperand())
     return false;
+  if (!Earlier.getValueType() || !Later.getValueType() ||
+      Earlier.getValueType() != Later.getValueType())
+    return false;
   if (Earlier.getMatchingId() != Later.getMatchingId())
     return false;
   // At the moment, we don't remove ordered stores, but do remove

diff  --git a/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
index bc278feb4ae88..b05fc802ca250 100644
--- a/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
+++ b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
@@ -30,3 +30,14 @@ define i32 @
diff erent_types_store(ptr %p, i32 %a) {
   %sub = sub i32 %a, %v2.c
   ret i32 %sub
 }
+
+define void @dse(ptr %p, i32 %i1, i8 %i2) {
+; CHECK-LABEL: @dse(
+; CHECK-NEXT:    store i32 [[I1:%.*]], ptr [[P:%.*]], align 4
+; CHECK-NEXT:    store i8 [[I2:%.*]], ptr [[P]], align 1
+; CHECK-NEXT:    ret void
+;
+  store i32 %i1, ptr %p
+  store i8 %i2, ptr %p
+  ret void
+}


        


More information about the llvm-commits mailing list