[PATCH] D98595: [NFC] Refactor the code to avoid check target type.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 13 19:30:31 PST 2021


LuoYuanke created this revision.
Herald added a subscriber: hiraditya.
LuoYuanke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98595

Files:
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -590,12 +590,12 @@
   // Note that we should not do this for pointer<->integer casts,
   // because that would result in type punning.
   if (LI.hasOneUse()) {
-    // Don't transform when the type is x86_amx, it makes the pass that lower
-    // x86_amx type happy.
     if (auto *BC = dyn_cast<BitCastInst>(LI.user_back())) {
-      assert(!LI.getType()->isX86_AMXTy() &&
-             "load from x86_amx* should not happen!");
-      if (BC->getType()->isX86_AMXTy())
+      // Prevent to bitcast the pointer if the cast is not lossless.
+      auto *DestPtrTy =
+          BC->getType()->getPointerTo(LI.getPointerAddressSpace());
+      auto *SrcPtrTy = LI.getPointerOperandType();
+      if (!SrcPtrTy->canLosslesslyBitCastTo(DestPtrTy))
         return nullptr;
     }
 
@@ -1121,12 +1121,10 @@
 
   // Fold away bit casts of the stored value by storing the original type.
   if (auto *BC = dyn_cast<BitCastInst>(V)) {
-    assert(!BC->getType()->isX86_AMXTy() &&
-           "store to x86_amx* should not happen!");
     V = BC->getOperand(0);
-    // Don't transform when the type is x86_amx, it makes the pass that lower
-    // x86_amx type happy.
-    if (V->getType()->isX86_AMXTy())
+    auto *DestPtrTy = V->getType()->getPointerTo(SI.getPointerAddressSpace());
+    auto *SrcPtrTy = SI.getPointerOperandType();
+    if (!SrcPtrTy->canLosslesslyBitCastTo(DestPtrTy))
       return false;
     if (!SI.isAtomic() || isSupportedAtomicType(V->getType())) {
       combineStoreToNewValue(IC, SI, V);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98595.330489.patch
Type: text/x-patch
Size: 1786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210314/29302111/attachment.bin>


More information about the llvm-commits mailing list