Skip to content

[mlir][Linalg] Bugfix in decompose generic by unfolding permutation #126737

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

Conversation

gdehame
Copy link
Contributor

@gdehame gdehame commented Feb 11, 2025

The pattern was returning success() by default which made the greedy pattern application act as if the IR was modified and even though nothing was changed and thus it can prevent it from converging for no legitimate reason.

The patch makes the rewrite pattern return failure() by default and success() if and only if the IR changed.

An example of unexpected behavior is by running mlir-opt input.mlir --linalg-specialize-generic-ops, we obtain an empty mlir as output with input.mlir as follows:

#map = affine_map<(d0) -> (d0)>
func.func @f(%arg0: tensor<8xi32>, %arg1: tensor<8xi32>) -> tensor<8xi32> {
  %0 = tensor.empty() : tensor<8xi32>
  %1 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel"]} ins(%arg0, %arg1: tensor<8xi32>, tensor<8xi32>) outs(%0: tensor<8xi32>) {
    ^bb0(%in: i32, %in_0: i32, %out: i32):
      %2 = arith.addi %in, %in_0: i32
      linalg.yield %2: i32
  } -> tensor<8xi32>
  return %1 : tensor<8xi32>
}

The pattern was returning success() by default which made the greedy pattern application act as if the IR was modified and even though nothing was changed and thus it can prevent it from converging for no legitimate reason.

The patch makes the rewrite pattern return failure() by default and success() if and only if the IR changed
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-mlir-linalg

@llvm/pr-subscribers-mlir

Author: None (gdehame)

Changes

The pattern was returning success() by default which made the greedy pattern application act as if the IR was modified and even though nothing was changed and thus it can prevent it from converging for no legitimate reason.

The patch makes the rewrite pattern return failure() by default and success() if and only if the IR changed.

An example of unexpected behavior is by running mlir-opt input.mlir --linalg-specialize-generic-ops with input.mlir as follows:

#map = affine_map&lt;(d0) -&gt; (d0)&gt;
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel"]} ins(%arg0, %arg1: tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0: tensor&lt;8xi32&gt;) {
    ^bb0(%in: i32, %in_0: i32, %out: i32):
      %2 = arith.addi %in, %in_0: i32
      linalg.yield %2: i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}

If we add the --debug option, we see that the DecomposeProjectedPermutation returns success() but the IR doesn't change and the pattern rewrite doesn't converge.

Output of mlir-opt input.mlir --linalg-specialize-generic-ops --debug :

Args: mlir-opt input.mlir --linalg-specialize-generic-ops --debug 
Load new dialect in Context builtin
ImplicitTypeIDRegistry::lookupOrInsert(mlir::FloatType)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ShapedType)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::MemRefLayoutAttrInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::BlobAttr)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::TypedAttr)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ElementsAttr)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DistinctAttr)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::BytecodeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SymbolOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpAsmOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RegionKindInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ConditionallySpeculatable)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::MemoryEffectOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ResourceBlobManagerDialectInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpAsmDialectInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::BytecodeDialectInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::AffineBinaryOpExprStorage)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::AffineConstantExprStorage)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::AffineDimExprStorage)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::AffineMapStorage)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::IntegerSetStorage)
Load new dialect in Context builtin
ImplicitTypeIDRegistry::lookupOrInsert(mlir::CastOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DestructurableTypeInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::LLVMTranslationDialectInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ZeroOperands&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::OneRegion&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ZeroResults&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ZeroSuccessors&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::NoRegionArguments&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::NoTerminator&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::SingleBlock&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::OpInvariants&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::BytecodeOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::AffineScope&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::IsIsolatedFromAbove&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::SymbolTable&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SymbolOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpAsmOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RegionKindInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::HasOnlyGraphRegion&lt;Empty&gt;)
Load new dialect in Context func
ImplicitTypeIDRegistry::lookupOrInsert(mlir::CallOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SymbolUserOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::CallableOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::FunctionOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RegionBranchTerminatorOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DialectInlinerInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ConvertToLLVMPatternInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::bufferization::BufferizableOpInterface)
Load new dialect in Context cf
Load new dialect in Context arith
ImplicitTypeIDRegistry::lookupOrInsert(mlir::arith::ArithFastMathInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::VectorUnrollOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::InferTypeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::InferIntRangeInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::arith::ArithIntegerOverflowFlagsInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::arith::ArithRoundingModeInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SelectLikeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::bufferization::BufferDeallocationOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ValueBoundsOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::bufferization::BufferViewFlowOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::BranchOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::mesh::ShardingInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::AutomaticAllocationScope&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::CallableOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::FunctionOpInterface::Trait&lt;Empty&gt;)
Load new dialect in Context tensor
Load new dialect in Context affine
Load new dialect in Context ub
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ub::PoisonAttrInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::affine::AffineDmaStartOp)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::affine::AffineMapAccessInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::affine::AffineDmaWaitOp)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::LoopLikeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RegionBranchOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::affine::AffineReadOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::affine::AffineWriteOpInterface)
Load new dialect in Context complex
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ReifyRankedShapedTypeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ShapedDimOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OffsetSizeAndStrideOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DestinationStyleOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::tensor::RelayoutOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::transform::FindPayloadReplacementOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SubsetOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SubsetInsertionOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::SubsetExtractionOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::TilingInterface)
Load new dialect in Context linalg
Load new dialect in Context math
Load new dialect in Context memref
ImplicitTypeIDRegistry::lookupOrInsert(mlir::CopyOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::PromotableMemOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DestructurableAccessorOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::PromotableAllocationOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DestructurableAllocationOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ViewLikeOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::bufferization::AllocationOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RuntimeVerifiableOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::AggregatedOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::LinalgOp)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::ContractionOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::ConvolutionOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::FillOpInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::PartialReductionOpInterface)
Load new dialect in Context scf
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ParallelCombiningOpInterface)
Ignoring repeated interface registration
Ignoring repeated interface registration
Ignoring repeated interface registration
Load new dialect in Context index
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ZeroRegions&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::OneResult&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::OneTypedResult&lt;mlir::RankedTensorType&gt;::Impl&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::VariadicOperands&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ConditionallySpeculatable::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::AlwaysSpeculatableImplTrait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::MemoryEffectOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::ReifyRankedShapedTypeOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::VariadicResults&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::SingleBlockImplicitTerminator&lt;mlir::linalg::YieldOp&gt;::Impl&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::AttrSizedOperandSegments&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::HasRecursiveMemoryEffects&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DestinationStyleOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::linalg::LinalgOp::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::OneTypedResult&lt;mlir::Type&gt;::Impl&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::NOperands&lt;2&gt;::Impl&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::IsCommutative&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::InferIntRangeInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::arith::ArithIntegerOverflowFlagsInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::SameOperandsAndResultType&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::VectorUnrollOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::Elementwise&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::Scalarizable&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::Vectorizable&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::Tensorizable&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::InferTypeOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::RegionBranchTerminatorOpInterface::Trait&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ReturnLike&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::IsTerminator&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::HasParent&lt;mlir::func::FuncOp&gt;::Impl&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::MemRefsNormalizable&lt;Empty&gt;)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::OpToOpPassAdaptor)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::DialectFoldInterface)
ImplicitTypeIDRegistry::lookupOrInsert(mlir::OpTrait::ConstantLike&lt;Empty&gt;)

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.return'(0x5ecbe5e16090) {
  "func.return"(%1) : (tensor&lt;8xi32&gt;) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.yield'(0x5ecbe5e17630) {
  "linalg.yield"(%2) : (i32) -&gt; ()

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'linalg.generic'(0x5ecbe5d9b560) {

  * Pattern mlir::linalg::LinalgSpecializationPattern : 'linalg.generic -&gt; ()' {
Trying to match "mlir::linalg::LinalgSpecializationPattern"
"mlir::linalg::LinalgSpecializationPattern" result 0
  } -&gt; failure : pattern failed to match

  * Pattern (anonymous namespace)::DecomposeProjectedPermutation : 'linalg.generic -&gt; ()' {
Trying to match "(anonymous namespace)::DecomposeProjectedPermutation"
"(anonymous namespace)::DecomposeProjectedPermutation" result 1
  } -&gt; success : pattern applied successfully
// *** IR Dump After Pattern Application ***
func.func @<!-- -->f(%arg0: tensor&lt;8xi32&gt;, %arg1: tensor&lt;8xi32&gt;) -&gt; tensor&lt;8xi32&gt; {
  %0 = tensor.empty() : tensor&lt;8xi32&gt;
  %1 = linalg.generic {indexing_maps = [affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;, affine_map&lt;(d0) -&gt; (d0)&gt;], iterator_types = ["parallel"]} ins(%arg0, %arg1 : tensor&lt;8xi32&gt;, tensor&lt;8xi32&gt;) outs(%0 : tensor&lt;8xi32&gt;) {
  ^bb0(%in: i32, %in_0: i32, %out: i32):
    %2 = arith.addi %in, %in_0 : i32
    linalg.yield %2 : i32
  } -&gt; tensor&lt;8xi32&gt;
  return %1 : tensor&lt;8xi32&gt;
}


} -&gt; success : pattern matched
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'arith.addi'(0x5ecbe5e170b0) {
  %2 = "arith.addi"(%arg2, %arg3) &lt;{overflowFlags = #arith.overflow&lt;none&gt;}&gt; : (i32, i32) -&gt; i32

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'func.func'(0x5ecbe5dc0ca0) {
} -&gt; failure : pattern failed to match
//===-------------------------------------------===//

//===-------------------------------------------===//
Processing operation : 'tensor.empty'(0x5ecbe5dffa60) {
  %0 = "tensor.empty"() : () -&gt; tensor&lt;8xi32&gt;

} -&gt; failure : pattern failed to match
//===-------------------------------------------===//
The pattern rewrite did not converge after scanning 10 times
ImplicitTypeIDRegistry::lookupOrInsert(mlir::detail::PreservedAnalyses::AllAnalysesType)


Full diff: https://github.com/llvm/llvm-project/pull/126737.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp (+2-1)
diff --git a/mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp b/mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp
index 83c4b5bdf109765..281a248681792ab 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/DecomposeGenericByUnfoldingPermutation.cpp
@@ -237,8 +237,9 @@ LogicalResult DecomposeProjectedPermutation::matchAndRewrite(
 
     newOp.getRegion().takeBody(op->getRegion(0));
     rewriter.replaceOp(op, newOp->getResults());
+    return success();
   }
-  return success();
+  return failure();
 }
 
 } // namespace

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes sense!

[nit] Would you mind updating the condition to:

  if (!isChanged) 
    return failure();

That would make more sense to me. Also, the summary will be used as the commit message. And the commit message should not include that lengthy debug dump. Steps to reproduce would be sufficient.

Thanks!

@gdehame
Copy link
Contributor Author

gdehame commented Feb 13, 2025

I changed the code to use an early exit and removed the dump from the summary

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Lets wait another day or two before landing - just in case some other reviewer decides to take a look.

If there's no new comments, please ping me here and I will land it for you. Thanks again!

Copy link

github-actions bot commented Feb 14, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@banach-space
Copy link
Contributor

@gdehame Please fix formatting :)

@rengolin rengolin merged commit a177be5 into llvm:main Feb 17, 2025
8 checks passed
Copy link

@gdehame Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

banach-space added a commit to banach-space/llvm-project that referenced this pull request Feb 18, 2025
Following on from llvm#126737, adds a negative test that:
* prior to llvm#126737, would incorrectly generated empty output,
* with the fix in-tree, simply outputs the input IR (i.e. the
  specialization "fails").

I've also made minor editorial changes.
banach-space added a commit that referenced this pull request Feb 18, 2025
…127600)

Following on from #126737, adds a negative test that:
* prior to #126737, would incorrectly generated empty output,
* with the fix in-tree, simply outputs the input IR (i.e. the
  specialization "fails").

I've also made minor editorial changes.
wldfngrs pushed a commit to wldfngrs/llvm-project that referenced this pull request Feb 19, 2025
…lvm#127600)

Following on from llvm#126737, adds a negative test that:
* prior to llvm#126737, would incorrectly generated empty output,
* with the fix in-tree, simply outputs the input IR (i.e. the
  specialization "fails").

I've also made minor editorial changes.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…lvm#126737)

The pattern was returning success() by default which made the greedy
pattern application act as if the IR was modified and even though
nothing was changed and thus it can prevent it from converging for no
legitimate reason.

The patch makes the rewrite pattern return failure() by default and
success() if and only if the IR changed.

An example of unexpected behavior is by running `mlir-opt input.mlir
--linalg-specialize-generic-ops`, we obtain an empty mlir as output with
`input.mlir` as follows:
```
#map = affine_map<(d0) -> (d0)>
func.func @f(%arg0: tensor<8xi32>, %arg1: tensor<8xi32>) -> tensor<8xi32> {
  %0 = tensor.empty() : tensor<8xi32>
  %1 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel"]} ins(%arg0, %arg1: tensor<8xi32>, tensor<8xi32>) outs(%0: tensor<8xi32>) {
    ^bb0(%in: i32, %in_0: i32, %out: i32):
      %2 = arith.addi %in, %in_0: i32
      linalg.yield %2: i32
  } -> tensor<8xi32>
  return %1 : tensor<8xi32>
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants