Loop Branch Elimination via Sub-Loop Splitting
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods for converting high-level computer programs into low-level code for execution often result in varying program lengths and execution times, with branch statements being a particular inefficiency due to their slower execution speed.
Innovation Solution
A method and apparatus that detect loop statements with branch statements, determine if they can be split into sub-loop statements without the branch statement, and remove the branch statement using either splitting or hyperblocking techniques, optimizing the program for faster execution.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If branch statements are used in loop statements to handle conditional logic, then program functionality and adaptability are improved, but execution speed deteriorates due to the overhead of branch prediction and pipeline flushing
Solution Approach 1:
The loop body is segmented into multiple versions based on the branch condition. Each version corresponds to a specific branch outcome (true or false), and only the relevant version is executed. This eliminates the need for branch prediction and reduces pipeline flushes, thereby improving execution speed while maintaining program functionality.
Solution Approach 2:
The compiler dynamically selects and generates different loop body versions based on the branch condition at compile time or runtime. This dynamic approach allows the program to adapt to different execution paths without incurring branch overhead, resolving the contradiction between adaptability and execution speed.
2Speed
If loop statements with branch statements are converted into multiple versions without branches, then execution speed is improved by eliminating branch overhead, but program complexity increases due to multiple code versions
Solution Approach 1:
The branch statement is extracted from the loop body, and the loop is rewritten in multiple versions without branches. Each version is optimized for a specific branch outcome, eliminating branch overhead. The compiler manages the multiple versions, reducing the visible complexity in the final executable code while improving execution speed.
Solution Approach 2:
Multiple copies of the loop body are created, each optimized for a specific branch condition. These copies are generated automatically by the compiler, and the complexity of managing multiple versions is abstracted away from the programmer. This approach improves execution speed by eliminating branch overhead while keeping the program structure manageable through automated code generation.
3Speed
If multiple versions of loop bodies are generated to eliminate branch statements, then execution speed improves, but compilation time and conversion complexity increase
Solution Approach 1:
The compiler performs preliminary analysis of branch conditions during compilation and pre-generates multiple versions of the loop body. This preliminary action allows the compiler to optimize the code before execution, reducing runtime overhead. While compilation time increases slightly, the gain in execution speed justifies the trade-off, and the compilation process is optimized to minimize the time penalty.
Solution Approach 2:
The compiler changes parameters such as loop unrolling factors, block sizes, and optimization levels to balance compilation time and execution speed. By adjusting these parameters, the compiler can generate multiple loop body versions efficiently, reducing the impact on compilation time while still achieving significant execution speed improvements through branch elimination.
Data Source
AI summary
Methods and apparatuses of converting a program, which may enhance an execution speed of a computer program, are provided. The method may include receiving a program, detecting at least one loop statement including at least one branch statement within the program, determining whether the loop statement may be split into at one or more sub-loop statements which perform the same function as a function of the loop statement and from which the branch statement has been removed, splitting the loop statement into the sub-loop statements and removing the branch statement included in the loop statement if it is determined that the loop statement may be split as a result of the determination, and outputting a result of removing the branch statement.


