[all-commits] [llvm/llvm-project] 8fca65: [LifetimeSafety] Optimize loan propagation by sepa...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Thu Nov 6 19:03:01 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8fca65c65e3aab9bfdb1a3252335a880689a3f61
      https://github.com/llvm/llvm-project/commit/8fca65c65e3aab9bfdb1a3252335a880689a3f61
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2025-11-06 (Thu, 06 Nov 2025)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/Facts.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/Origins.h
    M clang/lib/Analysis/LifetimeSafety/Facts.cpp
    M clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
    M clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
    M clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
    M clang/unittests/Analysis/LifetimeSafetyTest.cpp

  Log Message:
  -----------
  [LifetimeSafety] Optimize loan propagation by separating persistent and block-local origins (#165789)

## Summary

Optimizes the lifetime analysis loan propagation by preventing block-local origins from participating in expensive join operations at block boundaries.

## Problem

The lifetime analysis currently performs join operations on all origins at every block boundary. However, many origins are block-local: they exist only to propagate loans between persistent origins across temporary declarations and expressions within a single block. Including them in joins is unnecessary and expensive.

## Solution

This PR classifies origins into two categories:

- **Persistent origins**: referenced in multiple basic blocks, must participate in joins
- **Block-local origins**: confined to a single block, can be discarded at block boundaries

### Implementation

1. **Pre-pass** (`computePersistentOrigins`): Analyzes all facts in the CFG to identify which origins appear in multiple blocks
2. **Split lattice**: Maintains two separate `OriginLoanMap`s:
    - `PersistentOrigins`: participates in join operations
    - `BlockLocalOrigins`: used during block execution, discarded at boundaries
3. **Optimized join**: Only merges persistent origins; block-local map is reset to empty

### Benefits

- Significantly reduces join complexity, especially in functions with many temporary locals
- Performance scales with the ratio of temporary to persistent origins
- Correctness preserved: block-local loan propagation still works within blocks

Fixes: https://github.com/llvm/llvm-project/issues/165780

Fixes: https://github.com/llvm/llvm-project/issues/164625. It brings down regression from **150% to 2%**.

---



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list