I'm hitting an assert[1] in affine loop fusion when invoking replaceAllMemRefUsesWith from createPrivateMemRef.
It seems like we expect any affine.load/affine.store's map in the loop nest to always take all the loop nest indexes
as inputs. Unfortunately, that's not aways true. For example, the following affine.load map takes in only one index
out of two:
affine.for %arg3 = 0 to 20 { affine.for %arg4 = 0 to 512 { %ld = affine.load %tmp[%arg4 mod 128] : memref<128xf32> ... } }
Concretely, we pass outerIVs (%arg3 for the prev example) as extra operands in replaceAllMemRefUsesWith [2].
These extra operands are blindly used as map indexes in the memref replacement[3] regardless of the number of indexes
actually needed in the map.
[1] https://github.com/llvm/llvm-project/blob/master/mlir/lib/Transforms/Utils/Utils.cpp#L171
[2] https://github.com/llvm/llvm-project/blob/master/mlir/lib/Transforms/LoopFusion.cpp#L942
[3] https://github.com/llvm/llvm-project/blob/master/mlir/include/mlir/Transforms/Utils.h#L39
The current fix always defines a remapping for the memref replacement (indexRemap) with the proper number of inputs,
including all the outerIVs, so that the number of inputs and the operands provided for the map don't mismatch.
Another option would be to filter the indexes that are not used out of the extra operands provided to
replaceAllMemRefUsesWith, but the current fix looks cleaner to me.
Please, let me know if you have any other idea for the fix.
Thanks!
Diego
Do you also want to FileCheck the private memref's alloc / size?