← Latest papers
💻 computer science

Automated Loop Detection and Iteration Count Analysis in Binary Code

This paper presents an automated, scalable method that combines interprocedural static analysis with control-flow and data-dependency tracking to accurately detect natural loops and determine their iteration counts in optimized binary code, achieving high precision and scalability on real-world software and benchmark suites.

Original authors: Hayk Aslanyan, Garnik Khroyan, Shake Hakobyan, Hripsime Hovhannisyan

Published 2026-07-08
📖 5 min read🧠 Deep dive

Original authors: Hayk Aslanyan, Garnik Khroyan, Shake Hakobyan, Hripsime Hovhannisyan

Original paper licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a massive, ancient library filled with books written in a secret, coded language. This is your binary code—the raw, compiled instructions that a computer actually runs. You want to know how many times a specific story in the book repeats itself before it stops. In the world of programming, this is called a "loop."

However, there's a catch. Before the book reaches you, a very efficient editor (the compiler) has rewritten the story. They've removed the chapter headings, shuffled the paragraphs, and replaced simple words with complex symbols. Trying to count the repetitions by looking at the original story outline (the source code) is impossible because the final version looks completely different.

This paper presents a new automated detective tool designed to read this secret, coded language directly and answer two big questions:

  1. Where does the story loop? (Loop Detection)
  2. Exactly how many times does it repeat? (Iteration Count)

Here is how the tool works, broken down into simple steps:

1. The Map Maker (Disassembly & Control Flow)

First, the tool acts like a cartographer. It takes the raw, messy code and draws a map of the building.

  • It breaks the code down into "rooms" (called basic blocks).
  • It draws arrows showing which doors lead to which rooms.
  • It looks for back-alleys: paths where you can walk from a room back to a previous room you've already visited. This is the definition of a loop.
  • The Goal: To find "Natural Loops." Think of these as a merry-go-round with a single gate you must enter through. The tool ignores chaotic structures with multiple entry points (which are rare, about 10% of cases) because they are too messy to analyze accurately.

2. The Detective (Data Dependency)

Once the map is drawn, the tool becomes a detective tracking a specific suspect: the Iteration Variable.

  • This is the "counter" in the story (like a character named "John" who counts "1, 2, 3...").
  • The tool traces the "use-def chains." Imagine a trail of breadcrumbs. If the code says "John adds 1 to his score," the tool follows the breadcrumb back to see where John got his score from.
  • It checks: Does this character influence the decision to stop the loop? Does this character update their own score every time the loop runs? If yes, they are the Iteration Variable.

3. The Calculator (Solving the Equation)

Now that the tool knows who is counting and how they are counting, it acts like a mathematician.

  • It asks three questions:
    1. What was the starting number? (e.g., John starts at 0).
    2. How does the number change? (e.g., John adds 1 every time).
    3. When does the story end? (e.g., Stop when John reaches 10).
  • The tool simulates the instructions (like a mini-rehearsal) to figure out these numbers.
  • It then solves a simple math equation to predict exactly how many times the loop will run before hitting the "Stop" sign.

How Good Is It? (The Results)

The authors tested their detective tool on real-world software (like the tools used to manage files in Git or the text editor NeoVim) and a standard test suite called the Mälardalen WCET benchmark.

  • Accuracy: When the tool did give an answer, it was 100% correct. It never guessed wrong.
  • Coverage: It found the correct answer for about 60% of the loops in the test suite.
  • Comparison: It found more correct answers than other popular tools (like LLVM) combined with a decompiler, finding 27 extra loops that the others missed.
  • Speed: It is fast enough to be practical. It can process 1 million bytes of code in under 20 seconds. It successfully analyzed massive programs (like Git, which is 23 MB in size) without crashing.

The Limitations

The tool isn't a magic wand for every loop. It works best on "Natural Loops" (single entry point) where the counter changes in a straight, predictable line (like adding 1 or 2).

  • If a loop has multiple ways to enter, the tool skips it.
  • If the counter changes in a weird, non-linear way (like jumping around randomly), the tool can't solve the math equation and skips it.
  • Currently, it only speaks the language of AArch64 (a specific type of processor architecture used in many modern phones and servers).

Summary

In short, this paper introduces a smart, automated system that reads the "secret code" of computer programs. It draws a map to find loops, tracks the specific variables that count the repetitions, and uses math to predict exactly how long those loops will run. It is a highly accurate tool for understanding how optimized software behaves, which is crucial for making sure real-time systems (like those in cars or medical devices) don't get stuck in an infinite loop.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →