llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.04k stars 11.58k forks source link

MLIR Bufferization is generating leaky code #51389

Open joker-eph opened 2 years ago

joker-eph commented 2 years ago
Bugzilla Link 52047
Version unspecified
OS All
CC @jpienaar,@River707

Extended Description

Many tests in Integration/Dialect/Linalg/CPU are leaky (I'll disable the leak checker in Integration/Dialect/Linalg/CPU/lit.local.cfg for now).

Looking at a simple example like Integration/Dialect/Linalg/CPU/test-subtensor-insert.mlir which looks like:

func @​main() { %const = constant dense<10.0> : tensor<2xf32> %insert_val = constant dense<20.0> : tensor<1xf32> %inserted = tensor.insert_slice %insert_val into %const[0][1][1] : tensor<1xf32> into tensor<2xf32>

%unranked = tensor.cast %inserted : tensor<2xf32> to tensor<xf32> call @​print_memref_f32(%unranked) : (tensor<xf32>) -> ()

return }

Running through -linalg-bufferize -std-bufferize -tensor-constant-bufferize -tensor-bufferize -func-bufferize -finalizing-bufferize yield:

module { memref.global "private" constant @​__constant_1xf32 : memref<1xf32> = dense<2.000000e+01> memref.global "private" constant @​constant_2xf32 : memref<2xf32> = dense<1.000000e+01> func @​main() { %0 = memref.get_global @​constant_2xf32 : memref<2xf32> %1 = memref.get_global @​__constant_1xf32 : memref<1xf32> %2 = memref.alloc() : memref<2xf32> linalg.copy(%0, %2) : memref<2xf32>, memref<2xf32> %3 = memref.subview %2[0] [1] [1] : memref<2xf32> to memref<1xf32> linalg.copy(%1, %3) : memref<1xf32>, memref<1xf32> %4 = memref.cast %2 : memref<2xf32> to memref<xf32> call @​print_memref_f32(%4) : (memref<xf32>) -> () return } func private @​print_memref_f32(memref<*xf32>) }

An alloc was created but there clearly isn't any free here.

joker-eph commented 2 years ago

You can just repro locally by adding '-DLLVM_USE_SANITIZER=Address;Undefined' to your cmake invocation (I'm also building with clang as a host tool).

See the bot here: https://lab.llvm.org/staging/#/builders/191/builds/1595/ (your patch broke it, there is still one test not fixed)

sherhut commented 2 years ago

This should be fixed by https://reviews.llvm.org/D111059.

Not sure how to verify. Can you help Mehdi?

joker-eph commented 2 years ago

assigned to @joker-eph