Expand Up
@@ -68,4 +68,67 @@ func @empty_func() -> () {
return
}
// -----
// CHECK-LABEL: func @read_after_write_conflict(
func @read_after_write_conflict (%cst : f32 , %idx : index , %idx2 : index )
-> (f32 , f32 ) {
// CHECK-DAG: %[[alloc:.*]] = memref.alloc
// CHECK-DAG: %[[dummy:.*]] = "test.dummy_op"
// CHECK-DAG: %[[dummy_m:.*]] = bufferization.to_memref %[[dummy]]
%t = " test.dummy_op" () : () -> (tensor <10 xf32 >)
// CHECK: memref.copy %[[dummy_m]], %[[alloc]]
// CHECK: memref.store %{{.*}}, %[[alloc]]
%write = tensor.insert %cst into %t [%idx2 ] : tensor <10 xf32 >
// CHECK: %[[read:.*]] = "test.some_use"(%[[dummy]])
%read = " test.some_use" (%t ) : (tensor <10 xf32 >) -> (f32 )
// CHECK: %[[read2:.*]] = memref.load %[[alloc]]
%read2 = tensor.extract %write [%idx ] : tensor <10 xf32 >
// CHECK: memref.dealloc %[[alloc]]
// CHECK: return %[[read]], %[[read2]]
return %read , %read2 : f32 , f32
}
// -----
// CHECK-LABEL: func @copy_deallocated(
func @copy_deallocated () -> tensor <10 xf32 > {
// CHECK: %[[alloc:.*]] = memref.alloc()
%0 = linalg.init_tensor [10 ] : tensor <10 xf32 >
// CHECK: %[[alloc_tensor:.*]] = bufferization.to_tensor %[[alloc]]
// CHECK: memref.dealloc %[[alloc]]
// CHECK: return %[[alloc_tensor]]
return %0 : tensor <10 xf32 >
}
// -----
// CHECK-LABEL: func @buffer_not_deallocated(
// CHECK-SAME: %[[t:.*]]: tensor<?xf32>
func @buffer_not_deallocated (%t : tensor <?xf32 >, %c : i1 ) -> tensor <?xf32 > {
// CHECK: %[[r:.*]] = scf.if %{{.*}} {
%r = scf.if %c -> tensor <?xf32 > {
// CHECK: %[[some_op:.*]] = "test.some_op"
// CHECK: %[[alloc:.*]] = memref.alloc(%[[some_op]])
// CHECK: %[[casted:.*]] = memref.cast %[[alloc]]
// CHECK-NOT: dealloc
// CHECK: scf.yield %[[casted]]
%sz = " test.some_op" () : () -> (index )
%0 = linalg.init_tensor [%sz ] : tensor <?xf32 >
scf.yield %0 : tensor <?xf32 >
} else {
// CHECK: } else {
// CHECK: %[[m:.*]] = bufferization.to_memref %[[t]]
// CHECK: scf.yield %[[m]]
scf.yield %t : tensor <?xf32 >
}
// CHECK: }
// CHECK-NOT: dealloc
// CHECK: %[[r_tensor:.*]] = bufferization.to_tensor %[[r]]
// CHECK: return %[[r_tensor]]
return %r : tensor <?xf32 >
}