• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt -test-constant-fold -split-input-file %s | FileCheck %s
2
3// CHECK-LABEL: func @affine_apply
4func @affine_apply(%variable : index) -> (index, index, index) {
5  %c177 = constant 177 : index
6  %c211 = constant 211 : index
7  %N = constant 1075 : index
8
9  // CHECK:[[C1159:%.+]] = constant 1159 : index
10  // CHECK:[[C1152:%.+]] = constant 1152 : index
11  %x0 = affine.apply affine_map<(d0, d1)[S0] -> ( (d0 + 128 * S0) floordiv 128 + d1 mod 128)>
12           (%c177, %c211)[%N]
13  %x1 = affine.apply affine_map<(d0, d1)[S0] -> (128 * (S0 ceildiv 128))>
14           (%c177, %c211)[%N]
15
16  // CHECK:[[C42:%.+]] = constant 42 : index
17  %y = affine.apply affine_map<(d0) -> (42)> (%variable)
18
19  // CHECK: return [[C1159]], [[C1152]], [[C42]]
20  return %x0, %x1, %y : index, index, index
21}
22
23// -----
24
25// CHECK: #[[map:.*]] = affine_map<(d0, d1) -> (42, d1)
26
27func @affine_min(%variable: index) -> (index, index) {
28  // CHECK: %[[C42:.*]] = constant 42
29  %c42 = constant 42 : index
30  %c44 = constant 44 : index
31  // Partial folding will use a different map.
32  // CHECK: %[[r:.*]] = affine.min #[[map]](%[[C42]], %{{.*}})
33  %0 = affine.min affine_map<(d0, d1) -> (d0, d1)>(%c42, %variable)
34
35  // Full folding will remove the operation entirely.
36  // CHECK-NOT: affine.min
37  %1 = affine.min affine_map<(d0, d1) -> (d0, d1)>(%c42, %c44)
38
39  // CHECK: return %[[r]], %[[C42]]
40  return %0, %1 : index, index
41}
42
43// -----
44
45// CHECK: #[[map:.*]] = affine_map<(d0, d1) -> (42, d1)
46
47func @affine_min(%variable: index) -> (index, index) {
48  // CHECK: %[[C42:.*]] = constant 42
49  %c42 = constant 42 : index
50  // CHECK: %[[C44:.*]] = constant 44
51  %c44 = constant 44 : index
52  // Partial folding will use a different map.
53  // CHECK: %[[r:.*]] = affine.max #[[map]](%[[C42]], %{{.*}})
54  %0 = affine.max affine_map<(d0, d1) -> (d0, d1)>(%c42, %variable)
55
56  // Full folding will remove the operation entirely.
57  // CHECK-NOT: affine.max
58  %1 = affine.max affine_map<(d0, d1) -> (d0, d1)>(%c42, %c44)
59
60  // CHECK: return %[[r]], %[[C44]]
61  return %0, %1 : index, index
62}
63