@@ -156,8 +156,8 @@ private extension Function {
156156private func mergeStores( in function: Function , _ context: FunctionPassContext ) {
157157 for inst in function. instructions {
158158 if let store = inst as? StoreInst {
159- if let elementStores = getSequenceOfElementStores ( firstStore: store) {
160- merge ( elementStores: elementStores, context)
159+ if let ( elementStores, lastStore ) = getSequenceOfElementStores ( firstStore: store) {
160+ merge ( elementStores: elementStores, lastStore : lastStore , context)
161161 }
162162 }
163163 }
@@ -171,7 +171,7 @@ private func mergeStores(in function: Function, _ context: FunctionPassContext)
171171/// %addr_n = struct_element_addr %structAddr, #field_n
172172/// store %element_n to %addr_n
173173///
174- private func getSequenceOfElementStores( firstStore: StoreInst ) -> [ StoreInst ] ? {
174+ private func getSequenceOfElementStores( firstStore: StoreInst ) -> ( [ StoreInst ] , lastStore : StoreInst ) ? {
175175 guard let elementAddr = firstStore. destination as? StructElementAddrInst else {
176176 return nil
177177 }
@@ -195,7 +195,7 @@ private func getSequenceOfElementStores(firstStore: StoreInst) -> [StoreInst]? {
195195 numStoresFound += 1
196196 if numStoresFound == numElements {
197197 // If we saw `numElements` distinct stores, it implies that all elements in `elementStores` are not nil.
198- return elementStores. map { $0! }
198+ return ( elementStores. map { $0! } , lastStore : store )
199199 }
200200 default :
201201 if inst. mayReadOrWriteMemory {
@@ -206,8 +206,7 @@ private func getSequenceOfElementStores(firstStore: StoreInst) -> [StoreInst]? {
206206 return nil
207207}
208208
209- private func merge( elementStores: [ StoreInst ] , _ context: FunctionPassContext ) {
210- let lastStore = elementStores. last!
209+ private func merge( elementStores: [ StoreInst ] , lastStore: StoreInst , _ context: FunctionPassContext ) {
211210 let builder = Builder ( after: lastStore, context)
212211
213212 let structAddr = ( lastStore. destination as! StructElementAddrInst ) . struct
0 commit comments