File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/InstructionSimplification Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ swift_compiler_sources(Optimizer
12
12
SimplifyBranch.swift
13
13
SimplifyBuiltin.swift
14
14
SimplifyCondBranch.swift
15
+ SimplifyCondFail.swift
15
16
SimplifyGlobalValue.swift
16
17
SimplifyStrongRetainRelease.swift
17
18
SimplifyStructExtract.swift
Original file line number Diff line number Diff line change
1
+ //===--- SimplifyCondFail.swift -------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ import SIL
14
+
15
+ extension CondFailInst : OnoneSimplifyable {
16
+ func simplify( _ context: SimplifyContext ) {
17
+
18
+ /// Eliminates
19
+ /// ```
20
+ /// %0 = integer_literal 0
21
+ /// cond_fail %0, "message"
22
+ /// ```
23
+ if let literal = condition as? IntegerLiteralInst ,
24
+ literal. value. isZero ( ) {
25
+
26
+ context. erase ( instruction: self )
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=cond_fail | %FileCheck %s
2
+
3
+ // REQUIRES: swift_in_compiler
4
+
5
+ import Swift
6
+ import Builtin
7
+
8
+ // CHECK-LABEL: sil @not_failing
9
+ // CHECK-NOT: cond_fail
10
+ // CHECK: } // end sil function 'not_failing'
11
+ sil @not_failing : $@convention(thin) () -> () {
12
+ bb0:
13
+ %0 = integer_literal $Builtin.Int1, 0
14
+ cond_fail %0 : $Builtin.Int1, "not failing"
15
+ %r = tuple ()
16
+ return %r : $()
17
+ }
18
+
19
+ // CHECK-LABEL: sil @failing
20
+ // CHECK: cond_fail
21
+ // CHECK: } // end sil function 'failing'
22
+ sil @failing : $@convention(thin) () -> () {
23
+ bb0:
24
+ %0 = integer_literal $Builtin.Int1, -1
25
+ cond_fail %0 : $Builtin.Int1, "failing"
26
+ %r = tuple ()
27
+ return %r : $()
28
+ }
29
+
30
+ // CHECK-LABEL: sil @unknown
31
+ // CHECK: cond_fail
32
+ // CHECK: } // end sil function 'unknown'
33
+ sil @unknown : $@convention(thin) (Builtin.Int1) -> () {
34
+ bb0(%0 : $Builtin.Int1):
35
+ cond_fail %0 : $Builtin.Int1, "unknown"
36
+ %r = tuple ()
37
+ return %r : $()
38
+ }
39
+
You can’t perform that action at this time.
0 commit comments