Skip to content

Commit 54aacf6

Browse files
committed
SIL: don't allow upcast to be done on address types
It's not needed and just complicates the SIL
1 parent c6d5216 commit 54aacf6

File tree

7 files changed

+2
-84
lines changed

7 files changed

+2
-84
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ class SILBuilder {
11551155

11561156
UpcastInst *createUpcast(SILLocation Loc, SILValue Op, SILType Ty,
11571157
ValueOwnershipKind forwardingOwnershipKind) {
1158+
assert(Ty.isObject());
11581159
return insert(UpcastInst::create(getSILDebugLocation(Loc), Op, Ty,
11591160
getFunction(), forwardingOwnershipKind));
11601161
}

lib/IRGen/IRGenSIL.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,17 +6813,6 @@ void IRGenSILFunction::visitKeyPathInst(swift::KeyPathInst *I) {
68136813

68146814
void IRGenSILFunction::visitUpcastInst(swift::UpcastInst *i) {
68156815
auto toTy = getTypeInfo(i->getType()).getSchema()[0].getScalarType();
6816-
6817-
// If we have an address, just bitcast, don't explode.
6818-
if (i->getOperand()->getType().isAddress()) {
6819-
Address fromAddr = getLoweredAddress(i->getOperand());
6820-
llvm::Value *toValue = Builder.CreateBitCast(
6821-
fromAddr.getAddress(), toTy->getPointerTo());
6822-
Address Addr(toValue, toTy, fromAddr.getAlignment());
6823-
setLoweredAddress(i, Addr);
6824-
return;
6825-
}
6826-
68276816
Explosion from = getLoweredExplosion(i->getOperand());
68286817
Explosion to;
68296818
assert(from.size() == 1 && "class should explode to single value");

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,6 +4499,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44994499
void checkUpcastInst(UpcastInst *UI) {
45004500
require(UI->getType() != UI->getOperand()->getType(),
45014501
"can't upcast to same type");
4502+
require(UI->getType().isObject(), "cannot upcast address types");
45024503
checkNoTrivialToReferenceCast(UI);
45034504
if (UI->getType().is<MetatypeType>()) {
45044505
CanType instTy(UI->getType().castTo<MetatypeType>()->getInstanceType());

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,6 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
484484
return Builder.createUncheckedAddrCast(UADCI->getLoc(),
485485
OtherUADCI->getOperand(),
486486
UADCI->getType());
487-
488-
// (unchecked_addr_cast cls->superclass) -> (upcast cls->superclass)
489-
if (UADCI->getType() != UADCI->getOperand()->getType() &&
490-
UADCI->getType().isExactSuperclassOf(UADCI->getOperand()->getType()))
491-
return Builder.createUpcast(UADCI->getLoc(), UADCI->getOperand(),
492-
UADCI->getType());
493-
494487
return nullptr;
495488
}
496489

test/IRGen/upcast.sil

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/SILOptimizer/sil_combine.sil

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,19 +1194,6 @@ bb0(%0 : $E):
11941194
return %3 : $E
11951195
}
11961196

1197-
// (load (upcast-addr %x)) -> (upcast-ref (load %x))
1198-
// CHECK-LABEL: sil @load_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> B {
1199-
// CHECK: bb0
1200-
// CHECK-NEXT: load
1201-
// CHECK-NEXT: upcast
1202-
// CHECK-NEXT: return
1203-
sil @load_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> B {
1204-
bb0(%0 : $*E):
1205-
%1 = upcast %0 : $*E to $*B
1206-
%2 = load %1 : $*B
1207-
return %2 : $B
1208-
}
1209-
12101197
// CHECK-LABEL: sil @unchecked_enum_data_of_enum : $@convention(thin) () -> Builtin.Int1 {
12111198
// CHECK: bb0
12121199
// CHECK-NEXT: integer_literal

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,38 +1482,6 @@ bb0(%0 : @owned $E):
14821482
return %res : $()
14831483
}
14841484

1485-
// (load (upcast-addr %x)) -> (upcast-ref (load %x))
1486-
//
1487-
// CHECK-LABEL: sil [ossa] @load_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> @owned B {
1488-
// CHECK: bb0
1489-
// CHECK-NEXT: load
1490-
// CHECK-NEXT: upcast
1491-
// CHECK-NEXT: return
1492-
sil [ossa] @load_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> @owned B {
1493-
bb0(%0 : $*E):
1494-
%1 = upcast %0 : $*E to $*B
1495-
%2 = load [copy] %1 : $*B
1496-
return %2 : $B
1497-
}
1498-
1499-
// (load (upcast-addr %x)) -> (upcast-ref (load %x))
1500-
//
1501-
// CHECK-LABEL: sil [ossa] @loadborrow_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> @owned B {
1502-
// CHECK: bb0
1503-
// CHECK-NEXT: load_borrow
1504-
// CHECK-NEXT: upcast
1505-
// CHECK-NEXT: copy_value
1506-
// CHECK-NEXT: end_borrow
1507-
// CHECK-NEXT: return
1508-
sil [ossa] @loadborrow_upcast_addr_to_upcast_ref_load_canonicalization : $@convention(thin) (@inout E) -> @owned B {
1509-
bb0(%0 : $*E):
1510-
%1 = upcast %0 : $*E to $*B
1511-
%2 = load_borrow %1 : $*B
1512-
%3 = copy_value %2 : $B
1513-
end_borrow %2 : $B
1514-
return %3 : $B
1515-
}
1516-
15171485
// CHECK-LABEL: sil [ossa] @unchecked_enum_data_of_enum : $@convention(thin) () -> Builtin.Int1 {
15181486
// CHECK: bb0
15191487
// CHECK-NEXT: integer_literal

0 commit comments

Comments
 (0)