Collapsing dimensions of size 1 with random strides (a.k.a. non-contiguous w.r.t. collapsed dimensions) is a grey area that we'd like to clean-up. (See https://reviews.llvm.org/D136483#3909856)
That said, the implementation in memref-to-llvm currently skips dimensions of size 1 when computing the stride of a group.
While longer term we may want to clean that up, for now matches this behavior, at least in the static case.
For the dynamic case, for this patch we stick to min(group strides). However, if we want to handle the dynamic cases correctly while allowing non-truly-contiguous dynamic size of 1, we would need to if-then-else every dynamic size. In other words min(stride_i, for all i in group and dim_i != 1).
I didn't implement that in this patch at the moment since memref-to-llvm is technically broken in the general case for this. (It currently would only produce something sensible for row major tensors.)
If we need to support the dynamic case with "non-truly-contiguous" dimensions of size 1, we could do a quick and dirty fix here where we could generate:
The codegen won't be pretty, but it would be correct in the general case. I just don't know if it's worth it right now.
For the static case, it definitely worth it, because we see it happening in real workloads.
@springerm should be able to tell us if we need to support the dynamic case short term with the asserts he is adding for the dynamic cases.
Alternatively, @bkramer do you know if we need to support the dynamic case right now?