1 // RUN: mlir-opt -test-trait-folder %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
4 // Test that involutions fold correctly
5 //===----------------------------------------------------------------------===//
7 // CHECK-LABEL: func @testSingleInvolution
8 // CHECK-SAME: ([[ARG0:%.+]]: i32)
9 func.func @testSingleInvolution(%arg0 : i32) -> i32 {
10 // CHECK: [[INVOLUTION:%.+]] = "test.op_involution_trait_no_operation_fold"([[ARG0]])
11 %0 = "test.op_involution_trait_no_operation_fold"(%arg0) : (i32) -> i32
12 // CHECK: return [[INVOLUTION]]
16 // CHECK-LABEL: func @testDoubleInvolution
17 // CHECK-SAME: ([[ARG0:%.+]]: i32)
18 func.func @testDoubleInvolution(%arg0: i32) -> i32 {
19 %0 = "test.op_involution_trait_no_operation_fold"(%arg0) : (i32) -> i32
20 %1 = "test.op_involution_trait_no_operation_fold"(%0) : (i32) -> i32
21 // CHECK: return [[ARG0]]
25 // CHECK-LABEL: func @testTripleInvolution
26 // CHECK-SAME: ([[ARG0:%.+]]: i32)
27 func.func @testTripleInvolution(%arg0: i32) -> i32 {
28 // CHECK: [[INVOLUTION:%.+]] = "test.op_involution_trait_no_operation_fold"([[ARG0]])
29 %0 = "test.op_involution_trait_no_operation_fold"(%arg0) : (i32) -> i32
30 %1 = "test.op_involution_trait_no_operation_fold"(%0) : (i32) -> i32
31 %2 = "test.op_involution_trait_no_operation_fold"(%1) : (i32) -> i32
32 // CHECK: return [[INVOLUTION]]
36 //===----------------------------------------------------------------------===//
37 // Test that involutions fold occurs if operation fold fails
38 //===----------------------------------------------------------------------===//
40 // CHECK-LABEL: func @testFailingOperationFolder
41 // CHECK-SAME: ([[ARG0:%.+]]: i32)
42 func.func @testFailingOperationFolder(%arg0: i32) -> i32 {
43 %0 = "test.op_involution_trait_failing_operation_fold"(%arg0) : (i32) -> i32
44 %1 = "test.op_involution_trait_failing_operation_fold"(%0) : (i32) -> i32
45 // CHECK: return [[ARG0]]
49 //===----------------------------------------------------------------------===//
50 // Test that involution fold does not occur if operation fold succeeds
51 //===----------------------------------------------------------------------===//
53 // CHECK-LABEL: func @testInhibitInvolution
54 // CHECK-SAME: ([[ARG0:%.+]]: i32)
55 func.func @testInhibitInvolution(%arg0: i32) -> i32 {
56 // CHECK: [[OP:%.+]] = "test.op_involution_trait_succesful_operation_fold"([[ARG0]])
57 %0 = "test.op_involution_trait_succesful_operation_fold"(%arg0) : (i32) -> i32
58 %1 = "test.op_involution_trait_succesful_operation_fold"(%0) : (i32) -> i32
59 // CHECK: return [[OP]]
63 //===----------------------------------------------------------------------===//
64 // Test that idempotent folding works correctly
65 //===----------------------------------------------------------------------===//
67 // CHECK-LABEL: func @testSingleIdempotent
68 // CHECK-SAME: ([[ARG0:%.+]]: i32)
69 func.func @testSingleIdempotent(%arg0 : i32) -> i32 {
70 // CHECK: [[IDEMPOTENT:%.+]] = "test.op_idempotent_trait"([[ARG0]])
71 %0 = "test.op_idempotent_trait"(%arg0) : (i32) -> i32
72 // CHECK: return [[IDEMPOTENT]]
76 // CHECK-LABEL: func @testDoubleIdempotent
77 // CHECK-SAME: ([[ARG0:%.+]]: i32)
78 func.func @testDoubleIdempotent(%arg0: i32) -> i32 {
79 // CHECK: [[IDEMPOTENT:%.+]] = "test.op_idempotent_trait"([[ARG0]])
80 %0 = "test.op_idempotent_trait"(%arg0) : (i32) -> i32
81 %1 = "test.op_idempotent_trait"(%0) : (i32) -> i32
82 // CHECK: return [[IDEMPOTENT]]
86 // CHECK-LABEL: func @testTripleIdempotent
87 // CHECK-SAME: ([[ARG0:%.+]]: i32)
88 func.func @testTripleIdempotent(%arg0: i32) -> i32 {
89 // CHECK: [[IDEMPOTENT:%.+]] = "test.op_idempotent_trait"([[ARG0]])
90 %0 = "test.op_idempotent_trait"(%arg0) : (i32) -> i32
91 %1 = "test.op_idempotent_trait"(%0) : (i32) -> i32
92 %2 = "test.op_idempotent_trait"(%1) : (i32) -> i32
93 // CHECK: return [[IDEMPOTENT]]
97 // CHECK-LABEL: func @testBinaryIdempotent
98 // CHECK-SAME: ([[ARG0:%.+]]: i32)
99 func.func @testBinaryIdempotent(%arg0 : i32) -> i32 {
100 %0 = "test.op_idempotent_trait_binary"(%arg0, %arg0) : (i32, i32) -> i32
101 // CHECK: return [[ARG0]]