Skip to content

Commit 768a82f

Browse files
authored
Handle undefs in a few utilities used in RLE (#59448)
1 parent a0a0ebb commit 768a82f

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/swift/SILOptimizer/Utils/LoadStoreOptUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ class LSValue : public LSBase {
257257
SILValue materialize(SILInstruction *Inst) {
258258
if (CoveringValue)
259259
return SILValue();
260+
if (isa<SILUndef>(Base))
261+
return Base;
260262
auto Val = Base;
261263
auto InsertPt = getInsertAfterPoint(Base).getValue();
262264
SILBuilderWithScope Builder(InsertPt);

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,9 @@ SILBasicBlock::iterator swift::replaceSingleUse(Operand *use, SILValue newValue,
16831683
}
16841684

16851685
SILValue swift::makeCopiedValueAvailable(SILValue value, SILBasicBlock *inBlock) {
1686+
if (isa<SILUndef>(value))
1687+
return value;
1688+
16861689
if (!value->getFunction()->hasOwnership())
16871690
return value;
16881691

@@ -1698,6 +1701,9 @@ SILValue swift::makeCopiedValueAvailable(SILValue value, SILBasicBlock *inBlock)
16981701
}
16991702

17001703
SILValue swift::makeValueAvailable(SILValue value, SILBasicBlock *inBlock) {
1704+
if (isa<SILUndef>(value))
1705+
return value;
1706+
17011707
if (!value->getFunction()->hasOwnership())
17021708
return value;
17031709

test/SILOptimizer/redundant_load_elim.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,3 +1270,22 @@ bb0:
12701270
dealloc_stack_ref %1 : $AX
12711271
return %5 : $Int32
12721272
}
1273+
1274+
sil @read_emptytuple : $@convention(thin) (@in_guaranteed ()) -> ()
1275+
1276+
// CHECK-LABEL: sil @emptytuple_promotion :
1277+
// CHECK: store
1278+
// CHECK-LABEL: } // end sil function 'emptytuple_promotion'
1279+
sil @emptytuple_promotion : $@convention(thin) () -> () {
1280+
bb0:
1281+
%stk2 = alloc_stack $()
1282+
store undef to %stk2 : $*()
1283+
br bb1
1284+
1285+
bb1:
1286+
%ld = load %stk2 : $*()
1287+
dealloc_stack %stk2 : $*()
1288+
%r = tuple ()
1289+
return %r : $()
1290+
}
1291+

0 commit comments

Comments
 (0)