Files
swift-mirror/test/SILOptimizer/mem2reg_ossa_nontrivial_casts.sil
Erik Eckstein 7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00

82 lines
3.2 KiB
Plaintext

// RUN: %target-sil-opt -sil-print-types -enable-sil-verify-all %s -mem2reg | %FileCheck %s
import Builtin
import Swift
// We cannot use unchecked_value_cast for conversions to trivial type.
// Since it is forwarding, the ownership of the src forwards, but we cannot destroy the dst because it is trivial
// CHECK-LABEL: sil [ossa] @casttotrivial :
// CHECK: [[CAST:%.*]] = unchecked_bitwise_cast %0 : $AnyObject to $UInt8
// CHECK-NEXT: destroy_value %0 : $AnyObject
// CHECK-NEXT: return [[CAST]] : $UInt8
// CHECK-LABEL: } // end sil function 'casttotrivial'
sil [ossa] @casttotrivial : $@convention(thin) (@owned AnyObject) -> @owned UInt8 {
bb0(%0 : @owned $AnyObject):
%1 = alloc_stack $AnyObject
store %0 to [init] %1 : $*AnyObject
%2 = unchecked_addr_cast %1 : $*AnyObject to $*UInt8
%3 = load [trivial] %2 : $*UInt8
%4 = load [take] %1 : $*AnyObject
destroy_value %4 : $AnyObject
dealloc_stack %1 : $*AnyObject
return %3 : $UInt8
}
// We cannot use unchecked_value_cast, because it is forwarding, it forwards the src, and the src can no longer be used as a RunningVal
// To get rid of this issue we need to use a copy_value of the src, and make sure we don't generate copy_value in case of a load [copy].
// To avoid all this spl handling, just use bitwise cast
// CHECK-LABEL: sil [ossa] @casttonontrivial :
// CHECK: [[CAST:%.*]] = unchecked_bitwise_cast %0 : $AnyObject to $String
// CHECK: [[COPY:%.*]] = copy_value [[CAST]] : $String
// CHECK-NEXT: destroy_value %0 : $AnyObject
// CHECK-NEXT: return [[COPY]] : $String
// CHECK-LABEL: } // end sil function 'casttonontrivial'
sil [ossa] @casttonontrivial : $@convention(thin) (@owned AnyObject) -> @owned String {
bb0(%0 : @owned $AnyObject):
%1 = alloc_stack $AnyObject
store %0 to [init] %1 : $*AnyObject
%2 = unchecked_addr_cast %1 : $*AnyObject to $*String
%3 = load [copy] %2 : $*String
%4 = load [take] %1 : $*AnyObject
destroy_value %4 : $AnyObject
dealloc_stack %1 : $*AnyObject
return %3 : $String
}
struct Pair { var lhs: AnyObject; var rhs: AnyObject }
// CHECK-LABEL: sil [ossa] @shorteningcast :
// CHECK: [[CAST:%.*]] = unchecked_bitwise_cast %0 : $Pair to $AnyObject
// CHECK: [[COPY:%.*]] = copy_value [[CAST]] : $AnyObject
// CHECK-NEXT: destroy_value %0 : $Pair
// CHECK-NEXT: return [[COPY]] : $AnyObject
// CHECK-LABEL: } // end sil function 'shorteningcast'
sil [ossa] @shorteningcast : $@convention(thin) (@owned Pair) -> @owned AnyObject {
bb0(%0 : @owned $Pair):
%1 = alloc_stack $Pair
store %0 to [init] %1 : $*Pair
%2 = unchecked_addr_cast %1 : $*Pair to $*AnyObject
%3 = load [copy] %2 : $*AnyObject
%4 = load [take] %1 : $*Pair
destroy_value %4 : $Pair
dealloc_stack %1 : $*Pair
return %3 : $AnyObject
}
// CHECK-LABEL: sil [ossa] @deadcast :
// CHECK-LABEL: bb0
// CHECK-NEXT: destroy_value %0 : $AnyObject
// CHECK-LABEL: } // end sil function 'deadcast'
sil [ossa] @deadcast : $@convention(thin) (@owned AnyObject) -> () {
bb0(%0 : @owned $AnyObject):
%1 = alloc_stack $AnyObject
store %0 to [init] %1 : $*AnyObject
%2 = unchecked_addr_cast %1 : $*AnyObject to $*String
destroy_addr %1 : $*AnyObject
dealloc_stack %1 : $*AnyObject
%4 = tuple()
return %4 : $()
}