File: simplify_cfg_select_enum.sil

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,511 bytes parent folder | download
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
}