Skip to content

Commit 06eaf6b

Browse files
committed
Disable SILCombine of unchecked_bitwise_cast to unchecked_ref_cast in OSSA
unchecked_ref_cast is a forwarding cast while unchecked_bitwise_cast is not. We cannot just convert one to other in OSSA. Disable it now.
1 parent 0ea5d05 commit 06eaf6b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI) {
472472
SILInstruction *
473473
SILCombiner::
474474
visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
475+
if (UBCI->getFunction()->hasOwnership())
476+
return nullptr;
477+
475478
// (unchecked_bitwise_cast Y->Z (unchecked_bitwise_cast X->Y x))
476479
// OR (unchecked_trivial_cast Y->Z (unchecked_bitwise_cast X->Y x))
477480
// ->

test/SILOptimizer/sil_combine.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sil_stage canonical
88
import Builtin
99
import Swift
1010

11+
class Klass {}
1112
class RawBuffer {}
1213
class HeapBufferStorage<T, U> : RawBuffer {}
1314

@@ -4116,3 +4117,16 @@ bb0:
41164117
%1 = load %0 : $*Int64
41174118
return %1 : $Int64
41184119
}
4120+
4121+
// Check for disabled optimization of unchecked_bitwise_cast to unchecked_ref_cast in ossa
4122+
// This test can be optimized when ossa is supported in the SILCombine for unchecked_bitwise_cast
4123+
// CHECK-LABEL: sil [ossa] @refcast :
4124+
// CHECK: unchecked_bitwise_cast
4125+
// CHECK-LABEL: } // end sil function 'refcast'
4126+
sil [ossa] @refcast : $@convention(thin) (@owned Klass) -> @owned Optional<Klass> {
4127+
bb0(%0 : @owned $Klass):
4128+
%1 = unchecked_bitwise_cast %0 : $Klass to $Optional<Klass>
4129+
%2 = copy_value %1 : $Optional<Klass>
4130+
destroy_value %0 : $Klass
4131+
return %2 : $Optional<Klass>
4132+
}

0 commit comments

Comments
 (0)