Merge pull request #8648 from aschwaighofer/fix_dead_store_bug_value_metatype
Fix DeadStoreElim by not lying about instruction semantics
diff --git a/include/swift/SIL/SILNodes.def b/include/swift/SIL/SILNodes.def
index 472efe0..8221f00 100644
--- a/include/swift/SIL/SILNodes.def
+++ b/include/swift/SIL/SILNodes.def
@@ -202,7 +202,7 @@
// Metatypes
INST(MetatypeInst, SILInstruction, metatype, None, DoesNotRelease)
- INST(ValueMetatypeInst, SILInstruction, value_metatype, None, DoesNotRelease)
+ INST(ValueMetatypeInst, SILInstruction, value_metatype, MayRead, DoesNotRelease)
INST(ExistentialMetatypeInst, SILInstruction, existential_metatype, MayRead, DoesNotRelease)
INST(ObjCProtocolInst, SILInstruction, objc_protocol, None, DoesNotRelease)
diff --git a/test/SILOptimizer/dead_store_elim.sil b/test/SILOptimizer/dead_store_elim.sil
index a0b038d..af7dcae 100644
--- a/test/SILOptimizer/dead_store_elim.sil
+++ b/test/SILOptimizer/dead_store_elim.sil
@@ -1417,3 +1417,19 @@
dealloc_stack %1 : $*AB
return %2 : $Builtin.Int1
}
+
+// CHECK-LABEL: dont_remove_store
+// CHECK: load
+// CHECK: store
+// CHECK: value_metatype
+// CHECK: return
+sil @dont_remove_store : $@convention(thin) (@in_guaranteed foo) -> () {
+bb0(%0 : $*foo):
+ %1 = alloc_stack $foo
+ %2 = load %0 : $*foo
+ store %2 to %1 : $*foo
+ %3 = value_metatype $@thick foo.Type, %1 : $*foo
+ dealloc_stack %1 : $*foo
+ %20 = tuple()
+ return %20 : $()
+}