File: remove-shape-constraints.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (56 lines) | stat: -rw-r--r-- 1,987 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -remove-shape-constraints -canonicalize <%s | FileCheck %s --dump-input=fail --check-prefixes=CANON,CHECK-BOTH
// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -remove-shape-constraints <%s | FileCheck %s --dump-input=fail --check-prefixes=REPLACE,CHECK-BOTH

// -----
// Check that cstr_broadcastable is removed.
//
// CHECK-BOTH: func @f
func.func @f(%arg0 : !shape.shape, %arg1 : !shape.shape) -> index {
  // REPLACE-NEXT: %[[WITNESS:.+]] = shape.const_witness true
  // REPLACE-NOT: shape.cstr_eq
  // REPLACE: shape.assuming %[[WITNESS]]
  // CANON-NEXT: test.source
  // CANON-NEXT: return
  %0 = shape.cstr_broadcastable %arg0, %arg1 : !shape.shape, !shape.shape
  %1 = shape.assuming %0 -> index {
    %2 = "test.source"() : () -> (index)
    shape.assuming_yield %2 : index
  }
  return %1 : index
}

// -----
// Check that cstr_eq is removed.
//
// CHECK-BOTH: func @f
func.func @f(%arg0 : !shape.shape, %arg1 : !shape.shape) -> index {
  // REPLACE-NEXT: %[[WITNESS:.+]] = shape.const_witness true
  // REPLACE-NOT: shape.cstr_eq
  // REPLACE: shape.assuming %[[WITNESS]]
  // CANON-NEXT: test.source
  // CANON-NEXT: return
  %0 = shape.cstr_eq %arg0, %arg1 : !shape.shape, !shape.shape
  %1 = shape.assuming %0 -> index {
    %2 = "test.source"() : () -> (index)
    shape.assuming_yield %2 : index
  }
  return %1 : index
}

// -----
// With a non-const value, we cannot fold away the code, but all constraints
// should be removed still.
//
// CHECK-BOTH: func @f
func.func @f(%arg0 : !shape.shape, %arg1 : !shape.shape) -> index {
  // CANON-NEXT: test.source
  // CANON-NEXT: return
  %0 = shape.cstr_broadcastable %arg0, %arg1 : !shape.shape, !shape.shape
  %1 = shape.cstr_eq %arg0, %arg1 : !shape.shape, !shape.shape
  %2 = shape.assuming_all %0, %1
  %3 = shape.assuming %0 -> index {
    %4 = "test.source"() : () -> (index)
    shape.assuming_yield %4 : index
  }
  return %3 : index
}