1// RUN: mlir-opt -test-trait-folder %s | FileCheck %s 2 3//===----------------------------------------------------------------------===// 4// Test that involutions fold correctly 5//===----------------------------------------------------------------------===// 6 7// CHECK-LABEL: func @testSingleInvolution 8// CHECK-SAME: ([[ARG0:%.+]]: i32) 9func @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]] 13 return %0: i32 14} 15 16// CHECK-LABEL: func @testDoubleInvolution 17// CHECK-SAME: ([[ARG0:%.+]]: i32) 18func @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]] 22 return %1: i32 23} 24 25// CHECK-LABEL: func @testTripleInvolution 26// CHECK-SAME: ([[ARG0:%.+]]: i32) 27func @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]] 33 return %2: i32 34} 35 36//===----------------------------------------------------------------------===// 37// Test that involutions fold occurs if operation fold fails 38//===----------------------------------------------------------------------===// 39 40// CHECK-LABEL: func @testFailingOperationFolder 41// CHECK-SAME: ([[ARG0:%.+]]: i32) 42func @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]] 46 return %1: i32 47} 48 49//===----------------------------------------------------------------------===// 50// Test that involution fold does not occur if operation fold succeeds 51//===----------------------------------------------------------------------===// 52 53// CHECK-LABEL: func @testInhibitInvolution 54// CHECK-SAME: ([[ARG0:%.+]]: i32) 55func @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]] 60 return %1: i32 61} 62 63//===----------------------------------------------------------------------===// 64// Test that idempotent folding works correctly 65//===----------------------------------------------------------------------===// 66 67// CHECK-LABEL: func @testSingleIdempotent 68// CHECK-SAME: ([[ARG0:%.+]]: i32) 69func @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]] 73 return %0: i32 74} 75 76// CHECK-LABEL: func @testDoubleIdempotent 77// CHECK-SAME: ([[ARG0:%.+]]: i32) 78func @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]] 83 return %1: i32 84} 85 86// CHECK-LABEL: func @testTripleIdempotent 87// CHECK-SAME: ([[ARG0:%.+]]: i32) 88func @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]] 94 return %2: i32 95} 96