Hello. When using commit cc2b2f548622805a883201bfd7732d863636ecac from llvm-project, I’m seeing an issue when trying to run the affine-loop-fusion pass in this example:
module {
memref.global @data : memref<100xf32> = dense<1.000000e+00>
func.func @foo(%arg0: memref<25xf32>) {
%cst_0 = arith.constant 0xFF800000 : f32
%0 = memref.get_global @data : memref<100xf32>
%alloc = memref.alloc() : memref<128xf32>
affine.for %arg1 = 0 to 128 {
affine.store %cst_0, %alloc[%arg1] : memref<128xf32>
}
%subview = memref.subview %alloc[0] [100] [1] : memref<128xf32> to memref<100xf32, strided<[1]>>
memref.copy %0, %subview : memref<100xf32> to memref<100xf32, strided<[1]>>
affine.for %arg1 = 0 to 25 {
%1 = affine.load %alloc[%arg1] : memref<128xf32>
%2 = affine.load %arg0[%arg1] : memref<25xf32>
%3 = arith.maximumf %2, %1 : f32
affine.store %3, %arg0[%arg1] : memref<25xf32>
}
return
}
}
When I run affine-loop-fusion, it doesn’t fuse the two loops, but for some reason it creates a private memref and ignores %alloc:
module {
memref.global @data : memref<100xf32> = dense<1.000000e+00>
func.func @foo(%arg0: memref<25xf32>) {
%alloc = memref.alloc() : memref<1xf32>
%cst = arith.constant 0xFF800000 : f32
%0 = memref.get_global @data : memref<100xf32>
%alloc_0 = memref.alloc() : memref<128xf32>
affine.for %arg1 = 0 to 128 {
affine.store %cst, %alloc_0[%arg1] : memref<128xf32>
}
%subview = memref.subview %alloc_0[0] [100] [1] : memref<128xf32> to memref<100xf32, strided<[1]>>
memref.copy %0, %subview : memref<100xf32> to memref<100xf32, strided<[1]>>
affine.for %arg1 = 0 to 25 {
affine.store %cst, %alloc[0] : memref<1xf32>
%1 = affine.load %alloc[0] : memref<1xf32>
%2 = affine.load %arg0[%arg1] : memref<25xf32>
%3 = arith.maximumf %2, %1 : f32
affine.store %3, %arg0[%arg1] : memref<25xf32>
}
return
}
}
Is this behavior expected? Or is it a possible bug? If the memref.copy operation is applied directly over %alloc (instead of a subview), I don’t see this same behavior. So I assume the pass could be missing some alias/subview analysis?