Open
Description
-normalize-memrefs
on
#map = affine_map<(d0, d1) -> (d1, d0)>
func.func @forward(%arg0: index, %arg1: index) {
%alloc = memref.alloc() : memref<85x40xf32, #map>
%8 = memref.load %alloc[%arg0, %arg1] : memref<85x40xf32, #map>
return
}
produces
func.func @forward(%arg0: index, %arg1: index) {
%alloc = memref.alloc() : memref<40x85xf32>
%0 = memref.load %alloc[%arg0, %arg1] : memref<40x85xf32>
return
}
where the indices into %alloc
within the memref.load have not been swapped as they should be.
I would expect the result to be
func.func @forward(%arg0: index, %arg1: index) {
%alloc = memref.alloc() : memref<40x85xf32>
%0 = memref.load %alloc[%arg1, %arg0] : memref<40x85xf32>
return
}
As comparison, applying this to the same IR with affine.load
:
func.func @affine(%arg0: index, %arg1: index) {
%alloc = memref.alloc() : memref<85x40xf32, #map>
%8 = affine.load %alloc[%arg0, %arg1] : memref<85x40xf32, #map>
return
}
results in a correct swap of the indices:
func.func @affine(%arg0: index, %arg1: index) {
%alloc = memref.alloc() : memref<40x85xf32>
%0 = affine.load %alloc[symbol(%arg1), symbol(%arg0)] : memref<40x85xf32>
return
}
Reproducer: https://godbolt.org/z/5Pffq5fKP