llvm-project

Форк
0
103 строки · 4.1 Кб
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)
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]]
13
  return %0: i32
14
}
15

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]]
22
  return %1: i32
23
}
24

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]]
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)
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]]
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)
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]]
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)
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]]
73
  return %0: i32
74
}
75

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]]
83
  return %1: i32
84
}
85

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]]
94
  return %2: i32
95
}
96

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]]
102
  return %0: i32
103
}
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.