[mlir] [VectorOps] Implement vector.constant_mask lowering to LLVM IR
Summary:
Makes this operation runnable on CPU by generating MLIR instructions
that are eventually folded into an LLVM IR constant for the mask.
Reviewers: nicolasvasilache, ftynse, reidtatge, bkramer, andydavis1
Reviewed By: nicolasvasilache, ftynse, andydavis1
Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79815
2020-05-13 08:07:29 +08:00
// RUN: mlir-opt %s -convert-vector-to-llvm | mlir-translate -mlir-to-llvmir | FileCheck %s
func @genbool_1d ( ) -> vector < 8x i1 > {
%0 = vector . constant _mask [ 4 ] : vector < 8x i1 >
return %0 : vector < 8x i1 >
}
// CHECK-LABEL: @genbool_1d()
// CHECK-NEXT: ret <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>
func @genbool_2d ( ) -> vector < 4x4x i1 > {
%v = vector . constant _mask [ 2 , 2 ] : vector < 4x4x i1 >
return %v : vector < 4x4x i1 >
}
// CHECK-LABEL: @genbool_2d()
// CHECK-NEXT: ret [4 x <4 x i1>] [<4 x i1> <i1 true, i1 true, i1 false, i1 false>, <4 x i1> <i1 true, i1 true, i1 false, i1 false>, <4 x i1> zeroinitializer, <4 x i1> zeroinitializer]
func @genbool_3d ( ) -> vector < 2x3x4x i1 > {
%v = vector . constant _mask [ 1 , 1 , 3 ] : vector < 2x3x4x i1 >
return %v : vector < 2x3x4x i1 >
}
// CHECK-LABEL: @genbool_3d()
// CHECK-NEXT: ret [2 x [3 x <4 x i1>]] {{\[+}}3 x <4 x i1>] [<4 x i1> <i1 true, i1 true, i1 true, i1 false>, <4 x i1> zeroinitializer, <4 x i1> zeroinitializer], [3 x <4 x i1>] zeroinitializer]
// note: awkward syntax to match [[
[mlir] [VectorOps] Implement vector.create_mask lowering to LLVM IR
Summary:
First, compact implementation of lowering to LLVM IR. A bit more
challenging than the constant mask due to the dynamic indices, of course.
I like to hear if there are more efficient ways of doing this in LLVM,
but this for now at least gives us a functional reference implementation.
Reviewers: nicolasvasilache, ftynse, bkramer, reidtatge, andydavis1, mehdi_amini
Reviewed By: nicolasvasilache
Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79954
2020-05-15 03:03:43 +08:00
func @genbool_1d_var_but_constant ( ) -> vector < 8x i1 > {
%i = constant 0 : index
%v = vector . create_mask %i : vector < 8x i1 >
return %v : vector < 8x i1 >
}
// CHECK-LABEL: @genbool_1d_var_but_constant()
// CHECK-NEXT: ret <8 x i1> zeroinitializer