agentleFS
rainoftimerainoftime/pl-skills/loop-optimizer/SKILL.md

loop-optimizer

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Optimize loops through transformations like unrolling, fusion, tiling, and vectorization.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Consider unrolling factor carefully (code size vs.

    line 44
  2. Distinctive:

    When code size matters more than speed

    line 86
  3. Distinctive:

    When loops have complex control flow

    line 87

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Loop Optimizer

Loop optimizations transform loops to improve performance by reducing overhead, increasing parallelism, and improving cache locality. Since programs spend most time in loops, these optimizations are critical for performance.

When to Use This Skill

  • Building optimizing compilers
  • Improving numerical code performance
  • Enabling vectorization
  • Optimizing for cache hierarchy
  • Parallelizing loop nests

What This Skill Does

  1. Loop Unrolling: Replicate loop body to reduce branch overhead
  2. Loop Fusion: Combine multiple loops into one
  3. Loop Tiling: Reorganize iteration for cache locality
  4. Loop Vectorization: Transform for SIMD execution
  5. Loop Interchange: Reorder nested loops for memory access

Key Concepts

ConceptDescription
Loop UnrollingReplicate body to reduce branch overhead
Loop FusionCombine loops with same bounds
Loop TilingReorganize for cache blocks
Loop InterchangeSwap nested loop order
VectorizationExecute multiple iterations in parallel

Tips

  • Profile before optimizing (identify hot loops)
  • Consider unrolling factor carefully (code size vs. speed)
  • Tile for L1 cache size (typically 32KB)
  • Align data for vectorization
  • Combine transformations synergistically

Common Use Cases

  • Matrix operations (multiply, transpose)
  • Image processing kernels
  • Scientific computing
  • Machine learning operators
  • Compression/decompression

Related Skills

  • dataflow-analysis-framework - Dependency analysis
  • constant-propagation-pass - Combine with loop optimizations
  • llvm-backend-generator - LLVM loop passes
  • ssa-constructor - Loop in SSA form

Canonical References

ReferenceWhy It Matters
Lam, Rothberg & Wolf, "The Cache Performance and Optimizations of Blocked Algorithms" (PLDI 1991)Classic paper on tiling for cache locality
Wolf & Lam, "A Data Locality Optimizing Algorithm" (PLDI 1991)Unified loop transformation framework
Allen & Kennedy, "Optimizing Compilers for Modern Architectures: A Dependence-based Approach" (Morgan Kaufmann, 2001)Comprehensive textbook on loop optimization
Feautrier, "Dataflow Analysis of Array and Scalar References" (IJPP 1991)Polyhedral model foundations

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
UnrollingReduces overheadCode bloat
TilingCache friendlyComplex bounds
VectorizationSIMD speedupAlignment requirements

When NOT to Use This Skill

  • Non-critical loops
  • When code size matters more than speed
  • When loops have complex control flow

Limitations

  • Requires dependency analysis
  • May increase code size
  • Hardware-specific tuning needed

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
CorrectnessPreserves loop semantics
PerformanceMeasurable speedup
GeneralityHandles various loop patterns
SafetyChecks for dependencies

Quality Indicators

✅ Good: Correct transformation, significant speedup, handles dependencies ⚠️ Warning: Works for simple cases, fails on complex dependencies ❌ Bad: Breaks semantics, incorrect loop bounds

Research Tools & Artifacts

Real-world loop optimization tools:

ToolWhy It Matters
LLVM loop passesProduction loop opts
GCC tree-ssaGCC loop optimization
Polly (LLVM)Polyhedral optimization
ISLInteger set library

Key Systems

  • Polly: Polyhedral optimization
  • Halide: Loop optimization DSL

Research Frontiers

Current loop optimization research:

DirectionKey PapersChallenge
Polyhedral"Polyhedral Model"Scalability
Auto-tuning"Auto-tuning Loops"Search
SIMD"Auto-vectorization"Vector width

Hot Topics

  1. ML for loops: Learning loop transforms
  2. Quantum loops: Loop optimization for quantum

Implementation Pitfalls

Common loop optimization bugs:

PitfallReal ExamplePrevention
DependenciesWrong dependenceAnalysis
OverflowLoop bounds overflowCareful math
AlignmentVector alignmentPad arrays

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.