Skip to content

Commit 0b2a58d

Browse files
committed
Bailout from silcombine/simplification that creates unoptimizable copies
1 parent c632c0d commit 0b2a58d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ SILValue InstSimplifier::visitEnumInst(EnumInst *EI) {
292292
}
293293

294294
SILValue InstSimplifier::visitAddressToPointerInst(AddressToPointerInst *ATPI) {
295+
if (ATPI->getFunction()->hasOwnership()) {
296+
return SILValue();
297+
}
295298
// (address_to_pointer (pointer_to_address x [strict])) -> x
296299
// The 'strict' flag is only relevant for instructions that access memory;
297300
// the moment the address is cast back to a pointer, it no longer matters.
@@ -303,6 +306,9 @@ SILValue InstSimplifier::visitAddressToPointerInst(AddressToPointerInst *ATPI) {
303306
}
304307

305308
SILValue InstSimplifier::visitPointerToAddressInst(PointerToAddressInst *PTAI) {
309+
if (PTAI->getFunction()->hasOwnership()) {
310+
return SILValue();
311+
}
306312
// If this address is not strict, then it cannot be replaced by an address
307313
// that may be strict.
308314
if (auto *ATPI = dyn_cast<AddressToPointerInst>(PTAI->getOperand()))
@@ -313,6 +319,10 @@ SILValue InstSimplifier::visitPointerToAddressInst(PointerToAddressInst *PTAI) {
313319
}
314320

315321
SILValue InstSimplifier::visitRefToRawPointerInst(RefToRawPointerInst *RefToRaw) {
322+
if (RefToRaw->getFunction()->hasOwnership()) {
323+
return SILValue();
324+
}
325+
316326
// Perform the following simplification:
317327
//
318328
// (ref_to_raw_pointer (raw_pointer_to_ref x)) -> x

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,7 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
333333
ATPI->getOperand(),
334334
PTAI->getType());
335335
}
336-
337-
OwnershipRAUWHelper helper(ownershipFixupContext, PTAI,
338-
ATPI->getOperand());
339-
if (helper) {
340-
auto replacement = helper.prepareReplacement();
341-
auto *newInst = Builder.createUncheckedAddrCast(
342-
PTAI->getLoc(), replacement, PTAI->getType());
343-
helper.perform(newInst);
344-
return nullptr;
345-
}
336+
return nullptr;
346337
}
347338
}
348339

0 commit comments

Comments
 (0)