[PATCH] D94372: [X86][AMX] Prohibit pointer cast on load.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 9 22:10:33 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.

The load/store instruction will be transformed to amx intrinsics the the
pass of AMX type lowering. Prohibiting the pointer cast make that pass
happy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94372

Files:
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/test/Transforms/InstCombine/load.ll


Index: llvm/test/Transforms/InstCombine/load.ll
===================================================================
--- llvm/test/Transforms/InstCombine/load.ll
+++ llvm/test/Transforms/InstCombine/load.ll
@@ -422,3 +422,19 @@
   call void @use.v2.p1(<2 x i8 addrspace(1)*> %Y)
   ret <2 x i64> %X
 }
+
+define dso_local void @test_amx_load_store(<256 x i32>* %src, x86_amx* %dst) {
+entry:
+  %vec = load <256 x i32>, <256 x i32>* %src, align 64
+  %bc = bitcast <256 x i32> %vec to x86_amx
+  store x86_amx %bc, x86_amx* %dst
+  ret void
+}
+
+define dso_local void @test_amx_load_store2(<256 x i32>* %dst, x86_amx* %src) {
+entry:
+  %vec = load x86_amx, x86_amx* %src, align 64
+  %bc = bitcast x86_amx %vec to <256 x i32>
+  store <256 x i32> %bc, <256 x i32>* %dst
+  ret void
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -589,7 +589,15 @@
   // Fold away bit casts of the loaded value by loading the desired type.
   // Note that we should not do this for pointer<->integer casts,
   // because that would result in type punning.
-  if (LI.hasOneUse())
+  if (LI.hasOneUse()) {
+    // Don't transform when the type is x86_amx, it make the pass that lower
+    // x86_amx type happy.
+    if (auto *BC = dyn_cast<BitCastInst>(LI.user_back())) {
+      Value *V = BC->getOperand(0);
+      if (BC->getType()->isX86_AMXTy() || V->getType()->isX86_AMXTy())
+        return nullptr;
+    }
+
     if (auto* CI = dyn_cast<CastInst>(LI.user_back()))
       if (CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() ==
                                     CI->getDestTy()->isPtrOrPtrVectorTy())
@@ -599,6 +607,7 @@
           IC.eraseInstFromFunction(*CI);
           return &LI;
         }
+  }
 
   // FIXME: We should also canonicalize loads of vectors when their elements are
   // cast to other types.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94372.315649.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210110/a817e429/attachment.bin>


More information about the llvm-commits mailing list