Skip to content

Auto-optimization suggestions #24

@AveryClapp

Description

@AveryClapp

Feature Description

AI-powered suggestions for code changes to improve cache behavior.

Example

Input Code:

for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
        result[i][j] = a[i][j] + b[i][j];
    }
}

Analysis:

  • L1 hit rate: 65.3%
  • Issue: Row-major access conflicts with column-major storage

Suggestion:

// Loop interchange for better spatial locality
for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
        result[i][j] = a[i][j] + b[i][j];
    }
}

Optimization Categories

  1. Loop transformations
    • Interchange, tiling, unrolling
  2. Data layout
    • AoS → SoA conversion
    • Struct padding for false sharing
  3. Prefetch hints
    • __builtin_prefetch() insertion
  4. Compiler hints
    • __restrict, __assume_aligned()

Implementation

  • Pattern recognition for common anti-patterns
  • AST-based code transformation
  • Verify suggestions with re-analysis
  • Show before/after metrics

Files

  • backend/optimizer/ (new component)
  • backend/optimizer/PatternMatcher.cpp
  • backend/optimizer/CodeGenerator.cpp

Challenges

  • Requires understanding of code semantics
  • Need to preserve correctness
  • May need LLM integration for complex cases

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions