llvm-project/mlir/test/Transforms/test-pattern-selective-replacement.mlir
Mehdi Amini ecec7920c6
[mlir][func] Move return-type verification from ReturnOp to FuncOp (#184153)
Move the operand count and type checks for func.return from
ReturnOp::verify() into a new FuncOp::verify(). The verifier iterates
all blocks in the callable region, skipping terminators that are not
func.return (e.g. llvm.return or test.return that may appear during
dialect conversion).

Fix several invalid-IR tests that had func.func return types
inconsistent with the actual func.return operands. Previously these
mismatches were silent because block verification stopped at an earlier
expected error before reaching the func.return; now that
FuncOp::verify() runs before body verification, the return types must be
consistent.
2026-03-03 12:18:27 +01:00

16 lines
589 B
MLIR

// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-pattern-selective-replacement -verify-diagnostics %s | FileCheck %s
// Test that operations can be selectively replaced.
// CHECK-LABEL: @test1
// CHECK-SAME: %[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32
func.func @test1(%arg0: i32, %arg1 : i32) -> (i32, i32) {
// CHECK: arith.addi %[[ARG1]], %[[ARG1]]
// CHECK-NEXT: "test.return"(%[[ARG0]]
%cast = "test.cast"(%arg0, %arg1) : (i32, i32) -> (i32)
%non_terminator = arith.addi %cast, %cast : i32
"test.return"(%cast, %non_terminator) : (i32, i32) -> ()
}
// -----