File: control-flow-sink.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 (60 lines) | stat: -rw-r--r-- 1,633 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
57
58
59
60
// RUN: mlir-opt -split-input-file -control-flow-sink %s | FileCheck %s

// CHECK-LABEL: @test_scf_if_sink
// CHECK-SAME:  (%[[ARG0:.*]]: i1, %[[ARG1:.*]]: i32)
// CHECK: %[[V0:.*]] = scf.if %[[ARG0]]
// CHECK:   %[[V1:.*]] = arith.addi %[[ARG1]], %[[ARG1]]
// CHECK:   scf.yield %[[V1]]
// CHECK: else
// CHECK:   %[[V1:.*]] = arith.muli %[[ARG1]], %[[ARG1]]
// CHECK:   scf.yield %[[V1]]
// CHECK: return %[[V0]]
func.func @test_scf_if_sink(%arg0: i1, %arg1: i32) -> i32 {
  %0 = arith.addi %arg1, %arg1 : i32
  %1 = arith.muli %arg1, %arg1 : i32
  %result = scf.if %arg0 -> i32 {
    scf.yield %0 : i32
  } else {
    scf.yield %1 : i32
  }
  return %result : i32
}

// -----

func.func private @consume(i32) -> ()

// CHECK-LABEL: @test_scf_if_then_only_sink
// CHECK-SAME:  (%[[ARG0:.*]]: i1, %[[ARG1:.*]]: i32)
// CHECK: scf.if %[[ARG0]]
// CHECK:   %[[V0:.*]] = arith.addi %[[ARG1]], %[[ARG1]]
// CHECK:   call @consume(%[[V0]])
func.func @test_scf_if_then_only_sink(%arg0: i1, %arg1: i32) {
  %0 = arith.addi %arg1, %arg1 : i32
  scf.if %arg0 {
    func.call @consume(%0) : (i32) -> ()
    scf.yield
  }
  return
}

// -----

func.func private @consume(i32) -> ()

// CHECK-LABEL: @test_scf_if_double_sink
// CHECK-SAME:  (%[[ARG0:.*]]: i1, %[[ARG1:.*]]: i32)
// CHECK: scf.if %[[ARG0]]
// CHECK:   scf.if %[[ARG0]]
// CHECK:     %[[V0:.*]] = arith.addi %[[ARG1]], %[[ARG1]]
// CHECK:     call @consume(%[[V0]])
func.func @test_scf_if_double_sink(%arg0: i1, %arg1: i32) {
  %0 = arith.addi %arg1, %arg1 : i32
  scf.if %arg0 {
    scf.if %arg0 {
      func.call @consume(%0) : (i32) -> ()
      scf.yield
    }
  }
  return
}