File: simplify_cfg_select_enum.sil

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (60 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (2)
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: %target-sil-opt -enable-sil-verify-all %s -jumpthread-simplify-cfg | %FileCheck %s

// Two select_enum instructions must not be considered as the same "condition",
// even if they have the same enum operand.
// This test checks that SimplifyCFG does not remove a dominated terminator with
// such a condition.

sil_stage canonical

import Builtin
import Swift

enum E {
	case A
	case B
	case C
}

class Base { }

class Derived1 : Base { }

class Derived2 : Base { }

// CHECK-LABEL: sil @test_cond_br
// CHECK: select_enum
// CHECK: cond_br
// CHECK: integer_literal $Builtin.Int64, 1
// CHECK: select_enum
// CHECK: cond_br
// CHECK: integer_literal $Builtin.Int64, 2
// CHECK: integer_literal $Builtin.Int64, 3
// CHECK: return
sil @test_cond_br : $@convention(thin) (E, @owned Base, @owned Base, @owned Base, @owned Base) -> Builtin.Int64 {
bb0(%0 : $E, %1 : $Base, %2 : $Base, %3 : $Base, %4 : $Base):
  %t1 = integer_literal $Builtin.Int1, -1
  %f1 = integer_literal $Builtin.Int1, 0
  %s1 = select_enum %0 : $E, case #E.A!enumelt: %t1, default %f1 : $Builtin.Int1
  cond_br %s1, bb1, bb2

bb1:
  %i1 = integer_literal $Builtin.Int64, 1
  br bb5(%i1 : $Builtin.Int64)

bb2:
  %s2 = select_enum %0 : $E, case #E.B!enumelt: %t1, default %f1 : $Builtin.Int1
  cond_br %s2, bb3, bb4

bb3:
  %i2 = integer_literal $Builtin.Int64, 2
  br bb5(%i2 : $Builtin.Int64)

bb4:
  %i3 = integer_literal $Builtin.Int64, 3
  br bb5(%i3 : $Builtin.Int64)

bb5(%a3 : $Builtin.Int64):
  return %a3 : $Builtin.Int64
}