Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

MLIR Bufferization is generating leaky code #51014

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR52047
Status CONFIRMED
Importance P enhancement
Reported by Mehdi Amini (joker.eph@gmail.com)
Reported on 2021-10-02 20:41:15 -0700
Last modified on 2021-11-10 09:15:53 -0800
Version unspecified
Hardware PC All
CC jpienaar@google.com, riddleriver@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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.

Quuxplusone commented 3 years ago

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

Not sure how to verify. Can you help Mehdi?

Quuxplusone commented 3 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)