Skip to content

Commit 36e33a8

Browse files
authored
Merge pull request #77902 from eeckstein/fix-simplify-load
SimplifyLoad: fix removal of load operand instructions
2 parents 2161111 + 736d8d5 commit 36e33a8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyLoad.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ private func transitivelyErase(load: LoadInst, _ context: SimplifyContext) {
295295
context.erase(instruction: inst)
296296
return
297297
}
298-
let operandInst = inst.operands[0].value as! SingleValueInstruction
298+
guard let operandInst = inst.operands[0].value as? SingleValueInstruction else {
299+
return
300+
}
299301
context.erase(instruction: inst)
300302
inst = operandInst
301303
}

test/SILOptimizer/simplify_load.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,16 @@ bb0:
530530
return %2
531531
}
532532

533+
// CHECK-LABEL: sil @load_from_begin_cow_mutation :
534+
// CHECK: [[I:%.*]] = integer_literal $Builtin.Int64, 1
535+
// CHECK: return [[I]]
536+
// CHECK: } // end sil function 'load_from_begin_cow_mutation'
537+
sil @load_from_begin_cow_mutation : $@convention(thin) () -> Builtin.Int64 {
538+
bb0:
539+
%0 = global_value @gc : $D
540+
(%1, %2) = begin_cow_mutation %0
541+
%3 = ref_element_addr %2, #D.d
542+
%4 = load %3
543+
return %4
544+
}
545+

0 commit comments

Comments
 (0)