@@ -204,7 +204,7 @@ struct TransformParamsToConstRefContext
204
204
break ;
205
205
}
206
206
}
207
-
207
+
208
208
if (!isRelatedToUpdatedParam)
209
209
continue ;
210
210
@@ -274,7 +274,7 @@ struct TransformParamsToConstRefContext
274
274
void eliminateLoadStorePairsForEntryPoint (IRFunc* func)
275
275
{
276
276
List<IRInst*> toRemove;
277
-
277
+
278
278
// Look for patterns: load(ptr) followed by store(var, load_result)
279
279
// This can be optimized to direct pointer usage
280
280
for (auto block : func->getBlocks ())
@@ -285,17 +285,17 @@ struct TransformParamsToConstRefContext
285
285
{
286
286
auto storedValue = storeInst->getVal ();
287
287
auto destPtr = storeInst->getPtr ();
288
-
288
+
289
289
// Check if we're storing a load result
290
290
if (auto loadInst = as<IRLoad>(storedValue))
291
291
{
292
292
auto loadedPtr = loadInst->getPtr ();
293
-
293
+
294
294
// IMPORTANT: Only optimize if destPtr is a variable (kIROp_Var)
295
295
// Don't optimize stores to buffer elements or other meaningful destinations
296
296
if (!as<IRVar>(destPtr))
297
297
continue ;
298
-
298
+
299
299
// Check if this load has only one use (this store)
300
300
bool loadHasOnlyOneUse = true ;
301
301
UInt useCount = 0 ;
@@ -308,16 +308,16 @@ struct TransformParamsToConstRefContext
308
308
break ;
309
309
}
310
310
}
311
-
311
+
312
312
if (loadHasOnlyOneUse)
313
313
{
314
314
// Replace all uses of destPtr with loadedPtr
315
315
destPtr->replaceUsesWith (loadedPtr);
316
-
316
+
317
317
// Mark both instructions for removal
318
318
toRemove.add (storeInst);
319
319
toRemove.add (loadInst);
320
-
320
+
321
321
// Also remove the variable if it's only used by this store
322
322
if (auto varInst = as<IRVar>(destPtr))
323
323
{
@@ -335,14 +335,14 @@ struct TransformParamsToConstRefContext
335
335
toRemove.add (varInst);
336
336
}
337
337
}
338
-
338
+
339
339
changed = true ;
340
340
}
341
341
}
342
342
}
343
343
}
344
344
}
345
-
345
+
346
346
// Remove marked instructions
347
347
for (auto inst : toRemove)
348
348
{
@@ -450,17 +450,19 @@ struct TransformParamsToConstRefContext
450
450
}
451
451
452
452
// Handle entry point functions separately - they don't get processed by processFunc
453
- // but they still need load/store optimization for parameters that come from global parameters
453
+ // but they still need load/store optimization for parameters that come from global
454
+ // parameters
454
455
for (auto inst = module ->getModuleInst ()->getFirstChild (); inst; inst = inst->getNextInst ())
455
456
{
456
457
auto func = as<IRFunc>(inst);
457
458
if (!func || !func->isDefinition ())
458
459
continue ;
459
-
460
+
460
461
// Only process entry point functions that weren't already processed
461
462
if (!shouldProcessFunction (func))
462
463
{
463
- // For entry point functions, use a broader optimization since we don't have specific updatedParams
464
+ // For entry point functions, use a broader optimization since we don't have
465
+ // specific updatedParams
464
466
eliminateLoadStorePairsForEntryPoint (func);
465
467
}
466
468
}
0 commit comments