[PATCH] D139841: [mlir][test] Add expand-strided-metadata to lower-to-llvm
Quentin Colombet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 01:18:40 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d0ca6b68ce2: [mlir][test] Add expand-strided-metadata to lower-to-llvm (authored by qcolombet).
Changed prior to commit:
https://reviews.llvm.org/D139841?vs=482105&id=483091#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139841/new/
https://reviews.llvm.org/D139841
Files:
mlir/test/Dialect/LLVM/lower-to-llvm-e2e.mlir
mlir/test/lib/Dialect/LLVM/CMakeLists.txt
mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
Index: utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
===================================================================
--- utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
@@ -599,6 +599,7 @@
"//mlir:LinalgTransforms",
"//mlir:MathToLLVM",
"//mlir:MemRefToLLVM",
+ "//mlir:MemRefTransforms",
"//mlir:Pass",
"//mlir:ReconcileUnrealizedCasts",
"//mlir:SCFToControlFlow",
Index: mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
===================================================================
--- mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
+++ mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
@@ -24,6 +24,7 @@
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/Linalg/Passes.h"
+#include "mlir/Dialect/MemRef/Transforms/Passes.h"
#include "mlir/IR/DialectRegistry.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
@@ -68,6 +69,10 @@
options.reassociateFPReductions)));
// Convert Math to LLVM (always needed).
pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
+ // Expand complicated MemRef operations before lowering them.
+ pm.addPass(memref::createExpandStridedMetadataPass());
+ // The expansion may create affine expressions. Get rid of them.
+ pm.addPass(createLowerAffinePass());
// Convert MemRef to LLVM (always needed).
pm.addPass(createMemRefToLLVMConversionPass());
// Convert Func to LLVM (always needed).
Index: mlir/test/lib/Dialect/LLVM/CMakeLists.txt
===================================================================
--- mlir/test/lib/Dialect/LLVM/CMakeLists.txt
+++ mlir/test/lib/Dialect/LLVM/CMakeLists.txt
@@ -15,6 +15,7 @@
MLIRLinalgTransforms
MLIRMathToLLVM
MLIRMemRefToLLVM
+ MLIRMemRefTransforms
MLIRPass
MLIRReconcileUnrealizedCasts
MLIRSCFToControlFlow
Index: mlir/test/Dialect/LLVM/lower-to-llvm-e2e.mlir
===================================================================
--- /dev/null
+++ mlir/test/Dialect/LLVM/lower-to-llvm-e2e.mlir
@@ -0,0 +1,45 @@
+// RUN: mlir-opt %s -o - -test-lower-to-llvm -cse -split-input-file | FileCheck %s
+// Note: We run CSE here to make the pattern matching more direct.
+
+// Check that we properly lower to llvm memref operations that require to be
+// expanded first, like `memref.subview`.
+func.func @subview(%0 : memref<64x4xf32, strided<[4, 1], offset: 0>>, %arg0 : index, %arg1 : index, %arg2 : index)
+-> memref<?x?xf32, strided<[?, ?], offset: ?>> {
+ // CHECK-LABEL: @subview
+ // CHECK-SAME: %[[BASE:[^:]*]]: !llvm.ptr<f32>,
+ // CHECK-SAME: %[[BASE_ALIGNED:[^:]*]]: !llvm.ptr<f32>,
+ // CHECK-SAME: %[[BASE_OFFSET:[^:]*]]: i64,
+ // CHECK-SAME: %[[BASE_STRIDE0:[^:]*]]: i64,
+ // CHECK-SAME: %[[BASE_STRIDE1:[^:]*]]: i64,
+ // CHECK-SAME: %[[BASE_SIZE0:[^:]*]]: i64,
+ // CHECK-SAME: %[[BASE_SIZE1:[^:]*]]: i64,
+ // CHECK-SAME: %[[ARG0:[^:]*]]: i64,
+ // CHECK-SAME: %[[ARG1:[^:]*]]: i64,
+ // CHECK-SAME: %[[ARG2:[^:]*]]: i64)
+ // CHECK-SAME: -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>
+
+ // CHECK-DAG: %[[STRIDE0:.*]] = llvm.mlir.constant(4 : index) : i64
+ // CHECK-DAG: %[[DESCSTRIDE0:.*]] = llvm.mul %[[ARG0]], %[[STRIDE0]] : i64
+ // CHECK-DAG: %[[OFF2:.*]] = llvm.add %[[DESCSTRIDE0]], %[[ARG1]] : i64
+ // CHECK-DAG: %[[DESC:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+
+ // Base address and algined address.
+ // CHECK-DAG: %[[DESC0:.*]] = llvm.insertvalue %[[BASE]], %[[DESC]][0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+ // CHECK-DAG: %[[DESC1:.*]] = llvm.insertvalue %[[BASE_ALIGNED]], %[[DESC0]][1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+
+ // Offset.
+ // CHECK: %[[DESC2:.*]] = llvm.insertvalue %[[OFF2]], %[[DESC1]][2] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+ // Size 0.
+ // CHECK: %[[DESC3:.*]] = llvm.insertvalue %[[ARG0]], %[[DESC2]][3, 0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+ // Stride 0 == 4 * %arg0.
+ // CHECK: %[[DESC4:.*]] = llvm.insertvalue %[[DESCSTRIDE0]], %[[DESC3]][4, 0] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+ // Size 1.
+ // CHECK: %[[DESC5:.*]] = llvm.insertvalue %[[ARG1]], %[[DESC4]][3, 1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+ // Stride 1 == 1 * %arg1.
+ // CHECK: %[[DESC6:.*]] = llvm.insertvalue %[[ARG1]], %[[DESC5]][4, 1] : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
+
+ %1 = memref.subview %0[%arg0, %arg1][%arg0, %arg1][%arg0, %arg1] :
+ memref<64x4xf32, strided<[4, 1], offset: 0>>
+ to memref<?x?xf32, strided<[?, ?], offset: ?>>
+ return %1 : memref<?x?xf32, strided<[?, ?], offset: ?>>
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139841.483091.patch
Type: text/x-patch
Size: 4964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221215/07b23125/attachment.bin>
More information about the llvm-commits
mailing list