[Mlir-commits] [mlir] [mlir][func][bufferization] Fix cast incompatible when bufferize callOp (PR #105929)

Matthias Springer llvmlistbot at llvm.org
Sat Aug 24 09:28:33 PDT 2024


================
@@ -258,20 +258,25 @@ struct CallOpInterface
         return failure();
       Value buffer = *maybeBuffer;
 
-      // Caller / callee type mismatch is handled with a CastOp.
+      // Caller / callee type mismatch is handled with castOrReallocMemRefValue.
       auto memRefType = funcType.getInput(opOperand.getOperandNumber());
       // Since we don't yet have a clear layout story, to_memref may
       // conservatively turn tensors into more dynamic memref than necessary.
       // If the memref type of the callee fails, introduce an extra memref.cast
       // that will either canonicalize away or fail compilation until we can do
-      // something better.
+      // something better. Insert a reallocation + copy if it cannot be
+      // statically guaranteed that a direct cast would be valid.
       if (buffer.getType() != memRefType) {
-        assert(
-            memref::CastOp::areCastCompatible(buffer.getType(), memRefType) &&
-            "CallOp::bufferize: cast incompatible");
-        Value castBuffer = rewriter.create<memref::CastOp>(callOp.getLoc(),
-                                                           memRefType, buffer);
-        buffer = castBuffer;
+        auto memrefDestType = dyn_cast<MemRefType>(memRefType);
+        assert(memrefDestType &&
+               "buffer layout not supported on unranked tensors");
+        BufferizationOptions options;
----------------
matthias-springer wrote:

No, just take it directly from the given `options`.


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


More information about the Mlir-commits mailing list