Files
swift-mirror/test/SILOptimizer/simplify_cond_fail.sil
Erik Eckstein 16cb80b60d Optimizer: implement all of cond_fail simplification as instruction simplification
Inserts an unreachable after an unconditional fail:
```
  %0 = integer_literal 1
  cond_fail %0, "message"
  // following instructions
```
->
```
  %0 = integer_literal 1
  cond_fail %0, "message"
  unreachable
deadblock:
  // following instructions
```

Remove the old SILCombine implementation because it's not working well with OSSA lifetime completion.
This also required to move the `shouldRemoveCondFail` utility function from SILCombine to InstOptUtils.
2026-01-22 17:41:22 +01:00

60 lines
1.6 KiB
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=cond_fail | %FileCheck %s
// REQUIRES: swift_in_compiler
import Swift
import Builtin
// CHECK-LABEL: sil @not_failing
// CHECK-NOT: cond_fail
// CHECK: } // end sil function 'not_failing'
sil @not_failing : $@convention(thin) () -> () {
bb0:
%0 = integer_literal $Builtin.Int1, 0
cond_fail %0 : $Builtin.Int1, "not failing"
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil @failing
// CHECK: cond_fail
// CHECK-NEXT: unreachable
// CHECK: } // end sil function 'failing'
sil @failing : $@convention(thin) () -> () {
bb0:
%0 = integer_literal $Builtin.Int1, -1
cond_fail %0 : $Builtin.Int1, "failing"
br bb1
bb1:
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil [ossa] @dont_remove_lifetime_ending_instructions :
// CHECK: cond_fail
// CHECK-NEXT: end_borrow %1
// CHECK-NEXT: destroy_value [dead_end] %0
// CHECK-NEXT: unreachable
// CHECK: } // end sil function 'dont_remove_lifetime_ending_instructions'
sil [ossa] @dont_remove_lifetime_ending_instructions : $@convention(thin) (@owned String) -> () {
bb0(%0 : @owned $String):
%1 = begin_borrow %0
%2 = integer_literal $Builtin.Int1, -1
cond_fail %2 : $Builtin.Int1, "failing"
end_borrow %1
destroy_value [dead_end] %0
unreachable
}
// CHECK-LABEL: sil @unknown
// CHECK: cond_fail
// CHECK: } // end sil function 'unknown'
sil @unknown : $@convention(thin) (Builtin.Int1) -> () {
bb0(%0 : $Builtin.Int1):
cond_fail %0 : $Builtin.Int1, "unknown"
%r = tuple ()
return %r : $()
}