A memref_cast casting to a memref with a non identity map can't be lowered to llvm. Take the following test case:
#map1 = affine_map<(d0, d1)[s0, s1, s2] -> (d0 * s1 + s0 + d1 * s2)>
func @invalid_memref_cast(%arg0: memref<?x?xf64>) {
%c1 = constant 1 : index
%c0 = constant 0 : index
%5 = memref_cast %arg0 : memref<?x?xf64> to memref<?x?xf64, #map1>
%25 = std.subview %5[%c0, %c0][%c1, %c1][] : memref<?x?xf64, #map1> to memref<?x?xf64, #map1>
return
}When lowering the subview mlir was assuming %5 to have an llvm type (which is not the case as mlir failed to lower the memref_cast).
Something does not line up here: you are using dyn_cast which is supposed to be expecting a possible nullptr as a result, but then you add adding an assert, which implies this is an impossible case...
If you are using the assert just to get a “nicer” crash, then the pattern should be asserting on “isa<>” and using cast<>