8000 Fix in scalarization of select op variants. by copybara-service[bot] · Pull Request #2533 · google/xls · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix in scalarization of select op variants. #2533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions xls/contrib/mlir/IR/xls_ops.td
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,7 @@ def Xls_SelOp : Xls_Op<"sel", [
ShapesAreConsistent<["cases", "otherwise", "result"]>,
AttrSizedOperandSegments,
Elementwise,
Scalarizable,
TensorArrayTypeFungible]> {
Scalarizable]> {
let summary = "Select";
let description = [{
Selects between operands based on a selector value.
Expand Down Expand Up @@ -1190,8 +1189,7 @@ def Xls_OneHotSelOp : Xls_Op<"one_hot_sel", [
Pure,
ShapesAreConsistent<["cases", "result"]>,
Elementwise,
Scalarizable,
TensorArrayTypeFungible]> {
Scalarizable]> {
let summary = "One-hot select";
let description = [{
Selects between operands based on a one-hot selector, OR-ing all selected
Expand All @@ -1217,8 +1215,7 @@ def Xls_PrioritySelOp : Xls_Op<"priority_sel", [
Pure,
ShapesAreConsistent<["cases", "default_value", "result"]>,
Elementwise,
Scalarizable,
TensorArrayTypeFungible]> {
Scalarizable]> {
let summary = "Priority select";
let description = [{
Selects between operands based on a selector, choosing the highest-priority
Expand Down
27 changes: 25 additions & 2 deletions xls/contrib/mlir/testdata/scalarize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,32 @@ func.func @call_dslx_with_splat(%arg0: tensor<4xi32>, %arg1: i32) -> tensor<4xf3
}

// CHECK-LABEL: @select
// CHECK-NEXT: xls.sel
// CHECK-NEXT: return
func.func @select(%arg0: tensor<2xi32>, %arg1: tensor<2xi32>, %arg2: tensor<2xi1>) -> tensor<2xi32> attributes {xls = true} {
// CHECK-DAG: %[[ARG2_0:.*]] = "xls.array_index_static"(%arg2) <{index = 0 : i64}> : (!xls.array<2xi1>) -> i1
// CHECK-DAG: %[[ARG0_0:.*]] = "xls.array_index_static"(%arg0) <{index = 0 : i64}> : (!xls.array<2xi32>) -> i32
// CHECK-DAG: %[[ARG1_0:.*]] = "xls.array_index_static"(%arg1) <{index = 0 : i64}> : (!xls.array<2xi32>) -> i32
// CHECK-DAG: %[[SELECT_0:.*]] = xls.sel %[[ARG2_0]] in [%[[ARG1_0]]] else %[[ARG0_0]] : (i1, [i32], i32) -> i32
// CHECK-DAG: %[[ARG2_1:.*]] = "xls.array_index_static"(%arg2) <{index = 1 : i64}> : (!xls.array<2xi1>) -> i1
// CHECK-DAG: %[[ARG0_1:.*]] = "xls.array_index_static"(%arg0) <{index = 1 : i64}> : (!xls.array<2xi32>) -> i32
// CHECK-DAG: %[[ARG1_1:.*]] = "xls.array_index_static"(%arg1) <{index = 1 : i64}> : (!xls.array<2xi32>) -> i32
// CHECK-DAG: %[[SELECT_1:.*]] = xls.sel %[[ARG2_1]] in [%[[ARG1_1]]] else %[[ARG0_1]] : (i1, [i32], i32) -> i32
// CHECK-DAG: xls.array %[[SELECT_0]], %[[SELECT_1]] : (i32, i32) -> !xls.array<2xi32>
%0 = xls.sel %arg2 in [%arg1] else %arg0 : (tensor<2xi1>, [tensor<2xi32>], tensor<2xi32>) -> tensor<2xi32>
return %0 : tensor<2xi32>
}

// CHECK-LABEL: @priority_select
func.func @priority_select(%arg0: tensor<2xi16>, %arg1: tensor<2xi32>, %arg2: tensor<2xi32>) -> tensor<2xi32> attributes {xls = true} {
// CHECK: xls.priority_sel
// CHECK: xls.priority_sel
%0 = "xls.priority_sel"(%arg0, %arg1, %arg2) : (tensor<2xi16>, tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32>
return %0 : tensor<2xi32>
}

// CHECK-LABEL: @one_hot_select
func.func @one_hot_select(%arg0: tensor<2xi16>, %arg1: tensor<2xi32>, %arg2: tensor<2xi32>) -> tensor<2xi32> attributes {xls = true} {
// CHECK: xls.one_hot_sel
// CHECK: xls.one_hot_sel
%0 = "xls.one_hot_sel"(%arg0, %arg1, %arg2) : (tensor<2xi16>, tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32>
return %0 : tensor<2xi32>
}
0