# US 12,008,352 B2 · Transformation of a loop within computer code to minimize iterations

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,008,352 B2
- Document ID: US12008352B2
- Status: Granted
- Kind: B2
- Application number: 17/456,433
- Filed: 2021-11-24
- Published: 2023-05-25
- Granted: 2024-06-11
- Earliest claimed: 2021-11-24
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Wai Hung Tsang; Ettore Tiotto; Bardia Mahjour
- Web page: https://patentgrep.com/patent/US12008352B2

## CPC

- G06F 8/4441: {Reducing the execution time required by the program code}
- G06F 8/452: {Loops}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A loop within computer code is transformed to minimize loop iterations. A determination is made using statistical information relating to the loop whether the loop that has an early exit indication is to be transformed to minimize iterations of the loop. Based on determining that the loop is to be transformed, the loop is transformed.

## Claims

### Claim 1

A computer program product for facilitating processing within a computing environment, the computer program product comprising:
one or more computer readable storage media and program instructions collectively stored on the one or more computer readable storage media to perform a method comprising:
translating, using a compiler executing on a processor of the computing environment, source code of a computer program to machine code, the machine code including a loop that has an early exit indication, wherein the loop is terminated prior to a last iteration of the loop;
determining, by the compiler, using statistical information relating to the loop that has the early exit indication that the loop is to be transformed to minimize iterations of the loop to reach the early exit indication;
transforming the loop, by the compiler, based on determining that the loop is to be transformed, wherein the transforming the loop generates a transformed loop and wherein the transforming the loop changes how the transformed loop iterates such that the early exit indication in the transformed loop is reached in fewer iterations compared to the early exit indication in the loop prior to transformation; and
executing the machine code to perform a task of the computer program.

### Claim 2 (depends on 1)

The computer program product of claim 1, wherein the transforming the loop comprises performing loop reversal for the transformed loop.

### Claim 3 (depends on 1)

The computer program product of claim 1, wherein the transforming the loop includes:
splitting the loop into a plurality of loops having separate iteration spaces, the plurality of loops having a particular order; and
performing re-ordering of the plurality of loops, wherein at least one loop of the plurality of loops is in a different order from the particular order.

### Claim 4 (depends on 3)

The computer program product of claim 3, wherein the method further comprises determining from the loop a plurality of groups of iteration exit points of the loop, and wherein the splitting the loop into the plurality of loops is performed based on the plurality of groups.

### Claim 5 (depends on 4)

The computer program product of claim 4, wherein the determining the plurality of groups of iteration exit points of the loop comprises:
grouping the iteration exit points of the loop to obtain multiple candidate splitting groups;
sorting the multiple candidate splitting groups by a predefined order;
performing filtering on the multiple candidate splitting groups in which one or more candidate splitting groups is potentially eliminated from the multiple candidate splitting groups to obtain a set of candidate splitting groups; and
expanding the set of candidate splitting groups to provide the plurality of groups of iteration exit points of the loop used to provide the plurality of loops.

### Claim 6 (depends on 5)

The computer program product of claim 5, wherein the method further comprises:
determining that a given loop of the plurality of loops meets a defined criteria for loop reversal; and
performing loop reversal for the given loop based on determining that the given loop meets the defined criteria for loop reversal.

### Claim 7 (depends on 6)

The computer program product of claim 6, wherein the defined criteria for loop reversal includes having a higher probability of exiting the given loop toward an end of the given loop than a beginning of the given loop.

### Claim 8 (depends on 3)

The computer program product of claim 3, wherein the transforming the loop further includes performing loop reversal for at least one loop of the plurality of loops.

### Claim 9 (depends on 1)

The computer program product of claim 1, wherein the method further comprises checking that the loop qualifies for transformation, and wherein the determining that the loop is to be transformed is performed based on the checking indicating that the loop qualifies for transformation.

### Claim 10 (depends on 9)

The computer program product of claim 9, wherein the checking that the loop qualifies for transformation includes determining whether data dependencies of the loop will be preserved should transformation be performed.

### Claim 11

A computer system for facilitating processing within a computing environment, the computer system comprising:
a memory; and
at least one processor in communication with the memory, wherein the computer system is configured to perform a method, said method comprising:
translating, using a compiler executing on a processor of the computing environment, source code of a computer program to machine code, the machine code including a loop that has an early exit indication, wherein the loop is terminated prior to a last iteration of the loop;
determining, by the compiler, using statistical information relating to the loop that has the early exit indication that the loop is to be transformed to minimize iterations of the loop to reach the early exit indication;
transforming the loop, by the compiler, based on determining that the loop is to be transformed, wherein the transforming the loop generates a transformed loop and wherein the transforming the loop changes how the transformed loop iterates such that the early exit indication in the transformed loop is reached in fewer iterations compared to the early exit indication in the loop prior to transformation; and
executing the machine code to perform a task of the computer program.

### Claim 12 (depends on 11)

The computer system of claim 11, wherein the transforming the loop comprises performing loop reversal for the transformed loop.

### Claim 13 (depends on 11)

The computer system of claim 11, wherein the transforming the loop includes:
splitting the loop into a plurality of loops having separate iteration spaces, the plurality of loops having a particular order; and
performing re-ordering of the plurality of loops, wherein at least one loop of the plurality of loops is in a different order from the particular order.

### Claim 14 (depends on 13)

The computer system of claim 13, wherein the method further comprises determining from the loop a plurality of groups of iteration exit points of the loop, wherein the splitting the loop into the plurality of loops is performed based on the plurality of groups, and wherein the determining the plurality of groups of iteration exit points of the loop comprises:
grouping the iteration exit points of the loop to obtain multiple candidate splitting groups;
sorting the multiple candidate splitting groups by a predefined order;
performing filtering on the multiple candidate splitting groups in which one or more candidate splitting groups is potentially eliminated from the multiple candidate splitting groups to obtain a set of candidate splitting groups; and
expanding the set of candidate splitting groups to provide the plurality of groups of iteration exit points of the loop used to provide the plurality of loops.

### Claim 15

A computer-implemented method of facilitating processing within a computing environment, the computer-implemented method comprising:
translating, using a compiler executing on a processor of the computing environment, source code of a computer program to machine code, the machine code including a loop that has an early exit indication, wherein the loop is terminated prior to a last iteration of the loop;
determining, by the compiler, using statistical information relating to the loop that has the early exit indication that the loop is to be transformed to minimize iterations of the loop to reach the early exit indication;
transforming the loop, by the compiler, based on determining that the loop is to be transformed, wherein the transforming the loop generates a transformed loop and wherein the transforming the loop changes how the transformed loop iterates such that the early exit indication in the transformed loop is reached in fewer iterations compared to the early exit indication in the loop prior to being transformed; and
executing the machine code to perform a task of the computer program.

### Claim 16 (depends on 15)

The computer-implemented method of claim 15, wherein the transforming the loop comprises performing loop reversal for the transformed loop.

### Claim 17 (depends on 15)

The computer-implemented method of claim 15, wherein the transforming the loop includes:
splitting the loop into a plurality of loops having separate iteration spaces, the plurality of loops having a particular order; and
performing re-ordering of the plurality of loops, wherein at least one loop of the plurality of loops is in a different order from the particular order.

### Claim 18 (depends on 17)

The computer-implemented method of claim 17, further comprising determining from the loop a plurality of groups of iteration exit points of the loop, wherein the splitting the loop into the plurality of loops is performed based on the plurality of groups, and wherein the determining the plurality of groups of iteration exit points of the loop comprises:
grouping the iteration exit points of the loop to obtain multiple candidate splitting groups;
sorting the multiple candidate splitting groups by a predefined order;
performing filtering on the multiple candidate splitting groups in which one or more candidate splitting groups is potentially eliminated from the multiple candidate splitting groups to obtain a set of candidate splitting groups; and
expanding the set of candidate splitting groups to provide the plurality of groups of iteration exit points of the loop used to provide the plurality of loops.

### Claim 19 (depends on 17)

The computer-implemented method of claim 17, wherein the transforming the loop further includes performing loop reversal for at least one loop of the plurality of loops.

### Claim 20 (depends on 1)

The computer program product of claim 1, wherein the transforming the loop changes how the transformed loop iterates includes changing an order of indices of the transformed loop.
