Skip to content

Commit

Permalink
additional cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Mar 11, 2024
1 parent c6d0b87 commit 1995ae7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/Dialect/TensorExt/IR/TensorExtCanonicalization.td
Expand Up @@ -6,7 +6,7 @@ include "mlir/Dialect/Arith/IR/ArithOps.td"
include "mlir/Dialect/Tensor/IR/TensorOps.td"
include "mlir/IR/PatternBase.td"

// FIXME: refactor these helpers to a common file with InsertRotate.td
// TODO(#515): refactor these helpers to a common file with InsertRotate.td
defvar DefOverflow = ConstantEnumCase<Arith_IntegerOverflowAttr, "none">;

def MakeSingleResultVariadic: NativeCodeCall<"{ $0 }">;
Expand Down
5 changes: 3 additions & 2 deletions include/Dialect/TensorExt/Transforms/InsertRotate.td
Expand Up @@ -6,6 +6,8 @@ include "mlir/Dialect/Arith/IR/ArithOps.td"
include "mlir/Dialect/Tensor/IR/TensorOps.td"
include "mlir/IR/PatternBase.td"

// TODO(#512): Support target slot selection when the downstream op is an insert.

// The patterns in this file are intended to align with the automatic-SIMD
// batching heuristics from the HECO project. See section 4.4 of
// https://arxiv.org/abs/2202.01649 and the hir2hir passes in
Expand Down Expand Up @@ -40,6 +42,7 @@ foreach ArithOp = [Arith_AddIOp, Arith_SubIOp, Arith_MulIOp] in {

// Pre-align the first op's operands to the index that the result is
// used for in a subsequent op.
// TODO(#514): handle OuterOp with two different InnerOps on the LHS and RHS
foreach InnerOp = [Arith_AddIOp, Arith_SubIOp, Arith_MulIOp] in {
foreach OuterOp = [Arith_AddIOp, Arith_SubIOp, Arith_MulIOp] in {
// Left associated grouping handles (add (add (rotate t1 i1) (rotate t2 i2)) (rotate t3 i3))
Expand Down Expand Up @@ -75,8 +78,6 @@ foreach InnerOp = [Arith_AddIOp, Arith_SubIOp, Arith_MulIOp] in {
(TensorExt_RotateOp $output, $i3),
]
>;

// FIXME: do I need a pattern where OuterOp has two different InnerOp on the LHS and RHS?
}
}

Expand Down
1 change: 1 addition & 0 deletions include/Dialect/TensorExt/Transforms/Passes.td
Expand Up @@ -29,6 +29,7 @@ def InsertRotate : Pass<"insert-rotate"> {
let dependentDialects = ["mlir::heir::tensor_ext::TensorExtDialect"];
}

// TODO(#512): Investigate replacing this pattern with a tensor_ext.combine op
def CollapseInsertionChains : Pass<"collapse-insertion-chains"> {
let summary = "Collapse chains of extract/insert ops into rotate ops when possible";
let description = [{
Expand Down
10 changes: 4 additions & 6 deletions tests/tensor_ext/insert_rotations.mlir
@@ -1,6 +1,6 @@
// RUN: heir-opt --insert-rotate --canonicalize --cse %s | FileCheck %s

func.func @test_insert_rotation_for_add(%arg1: tensor<16xi32>) -> tensor<16xi32> {
func.func @test_insert_rotation_for_add(%arg1: tensor<16xi32>) -> i32 {
%c4 = arith.constant 4 : index
%c11 = arith.constant 11 : index
%c15 = arith.constant 15 : index
Expand All @@ -13,14 +13,11 @@ func.func @test_insert_rotation_for_add(%arg1: tensor<16xi32>) -> tensor<16xi32>

%extracted_1 = tensor.extract %arg1[%c4] : tensor<16xi32>
%2 = arith.addi %1, %extracted_1 : i32

%inserted = tensor.insert %2 into %arg1[%c4] : tensor<16xi32>
// FIXME: try also just returning the extracted value directly
return %inserted : tensor<16xi32>
return %2 : i32
}

// CHECK-LABEL: func @test_insert_rotation_for_add
// CHECK-SAME: (%[[arg0:.*]]: tensor<16xi32>) -> tensor<16xi32> {
// CHECK-SAME: (%[[arg0:.*]]: tensor<16xi32>) -> i32 {
// CHECK-NEXT: %[[c11:.*]] = arith.constant 11
// CHECK-NEXT: %[[c4:.*]] = arith.constant 4
// CHECK-NEXT: %[[c7:.*]] = arith.constant 7
Expand All @@ -29,3 +26,4 @@ func.func @test_insert_rotation_for_add(%arg1: tensor<16xi32>) -> tensor<16xi32>
// CHECK-NEXT: %[[v2:.*]] = arith.addi %[[v0]], %[[v1]] : tensor<16xi32>
// CHECK-NEXT: %[[v3:.*]] = arith.addi %[[v2]], %[[arg0]] : tensor<16xi32>
// CHECK-NEXT: %[[extracted:.*]] = tensor.extract %[[v3]][%[[c4]]] : tensor<16xi32>
// CHECK-NEXT: return

0 comments on commit 1995ae7

Please sign in to comment.