Compiler Loop Reformulation for Optimized Machine Code

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing compiler technologies are unable to optimize ill-formed loops, resulting in inefficient machine code generation and diminished performance due to the presence of loop exit statements within the loop body.

Innovation Solution

A method for reformulating single exit ill-formed loops (SEIFL) into transformed well-formed loops (TWFL) by duplicating code statements, adding labels, and incorporating conditional loop termination statements to create a reformulated code block that exits from the end of the loop, allowing for optimization and efficient machine code generation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If a loop contains a loop exit statement in the loop body, then the loop can exit during execution, but the compiler cannot optimize the loop resulting in inefficient machine code

Engineering Contradiction:
Improveloop exit capabilityVSAvoidcompilation optimization capability
Core Design Contradiction:
Adaptability or versatilityVSProductivity

Solution Approach 1:

The loop body is segmented into multiple basic blocks by introducing loop exit statements as separate blocks. Each segment can be independently analyzed and optimized, allowing the compiler to handle exit statements without preventing overall loop optimization.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

A loop exit statement acts as an intermediary between the loop body and the code following the loop. This mediator structure allows the compiler to insert optimization code before the exit point while maintaining the intended control flow, enabling optimizations that would otherwise be blocked by the exit statement.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If the compiler optimizes well-formed loops with scalar optimization, loop transformation, and automatic parallelization, then performance is improved, but ill-formed loops with exit statements cannot be optimized

Engineering Contradiction:
Improveexecution performanceVSAvoidloop structure complexity
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

Instead of trying to optimize the loop in-place with exit statements, the invention inverts the approach by constructing a new well-formed loop structure that replicates the original loop's behavior. The transformed loop without exit statements can be fully optimized, and the exit behavior is reconstructed through conditional jumps to the original exit points.

Inventive Principle:
Principle #13The other way round (Inversion)

Solution Approach 2:

The loop body is copied and transformed into a new loop structure. By creating a copy of the loop body without exit statements and adding appropriate conditional jumps, the invention enables the copied loop to be optimized while preserving the original loop's exit behavior through the jump instructions.

Inventive Principle:
Principle #26Copying

3Ease of operation

If loop exit statements are present in the loop body, then the loop can terminate early, but inefficient machine code is generated diminishing system performance

Engineering Contradiction:
Improveloop termination flexibilityVSAvoidsystem performance efficiency
Core Design Contradiction:
Ease of operationVSLoss of energy

Solution Approach 1:

The invention performs preliminary actions by analyzing the loop structure and identifying optimization opportunities before generating the final machine code. By pre-processing the loop to identify invariant code, compute bounds, and determine optimization strategies, the compiler can generate efficient machine code that maintains early termination capability while minimizing performance loss.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS7814468B1Method for loop reformulation
Publication Date: 2010.10.12 ORACLE AMERICAN INC
  • US7814468B1 patent drawing
  • US7814468B1 patent drawing
  • US7814468B1 patent drawing

AI summary

A method for loop reformulation is provided such that a single exit ill-formed loop (SEIFL) can be reformulated into a reformulated code block that contains a transformed well-formed loop (TWFL). A SEIFL loop is a loop that can exit from the loop body of the loop. After the loop reformulation, the TWFL of the reformulated code block can only exit from the end of the loop. The reformulated code block will replace the SEIFL in the compiler's internal representation (IR) such that a more efficient executable machine code can be generated by optimizing the reformulated compiler's IR.