# US 2022/0019435 A1 · Instruction cache behavior and branch prediction

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

- Number: US 2022/0019435 A1
- Document ID: US20220019435A1
- Status: Published application
- Kind: A1
- Application number: 16/933,197
- Filed: 2020-07-20
- Published: 2022-01-20
- Earliest claimed: 2020-07-20
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Yang LIU; Ting WANG; Qi LI; Qing ZHANG; Gui HAOCHEN; Xiao Ping GUO; Xiao Hua ZENG; Yangming WANG; Yi LI; Hua Qing LI; Fei FEI
- Web page: https://patentgrep.com/patent/US20220019435A1

## CPC

- G06F 9/30058: {Conditional branch instructions}
- G06F 9/3804: {for branches, e.g. hedging, branch folding}
- G06F 12/0875: with dedicated cache, e.g. instruction or stack
- G06F 12/0897: with two or more cache hierarchy levels (with multilevel cache hierarchies G06F12/0811)
- G06F 2212/1016: Performance improvement
- G06F 2212/452: Instruction code
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Instruction cache behavior and branch prediction are used to improve the functionality of a computing device by profiling branching instructions in an instruction cache to identify likelihoods of proceeding to a plurality of targets from the branching instructions; identifying a hot path in the instruction cache based on the identified likelihoods; and rearranging the plurality of targets relative to one another and associated branching instructions so that a first branching instruction that has a higher likelihood of proceeding to a first hot target than to a first cold target and that previously flowed to the first cold target and jumped to the first hot target instead flows to the first hot target and jumps to the first cold target.

## Claims

### Claim 1

A computer-implemented method comprising:
identifying a branching instruction associated with:
an origin instruction;
a cold target; and
a hot target located after the cold target in an instruction cache, wherein, based on historical data, the branching instruction is more likely to proceed to the hot target than to the cold target at execution based on a routing condition;
swapping an order of the cold target and the hot target in the instruction cache; and
reversing the routing condition.

### Claim 2 (depends on 1)

The computer-implemented method of claim 1, further comprising:
in response to determining that the cold target flows to the hot target at execution, inserting a jump instruction from to the hot target in the instruction cache after the swapped cold target.

### Claim 3 (depends on 1)

The computer-implemented method of claim 1, wherein execution of the branching instruction originally jumps to the hot target when the routing condition is a first one of true or false and originally flows to the cold target when the routing condition is a second one of true or false; and
wherein after swapping the order and reversing the routing condition, the execution of the branching instruction jumps to the cold target when the routing condition is the second one of true or false and flows to the hot target when the routing condition is the first one of true or false.

### Claim 4 (depends on 1)

The computer-implemented method of claim 1, further comprising after swapping the order of the cold target and the hot target in the instruction cache and reversing the routing condition:
executing instructions held in the instruction cache;
continuously monitoring execution of the instructions held in the instruction cache;
in response to determining that the branching instruction is more likely to proceed to the cold target than the hot target:
reclassifying the cold target as a new hot target;
reclassifying the hot target as a new cold target;
swapping a new order of the new cold target and the new hot target in the instruction cache; and
reversing the routing condition.

### Claim 5 (depends on 1)

The computer-implemented method of claim 1, wherein identifying the branching instruction further comprises determining that a difference in likelihood of proceeding to the hot target than to the cold target exceeds a user defined threshold.

### Claim 6 (depends on 1)

The computer-implemented method of claim 1, wherein the hot target is a first instruction in a hot block and the cold target is a first instruction in a cold block, wherein the cold target is initially located at a first address located in the instruction cache directly after a branch address where the branching instruction is located in the instruction cache, and wherein swapping the order of the cold target and the hot target in the instruction cache further comprises:
relocating the hot block in the instruction cache to begin with the hot target located at the first address; and
relocating the cold block in the instruction cache to begin with the cold target located at a second address.

### Claim 7 (depends on 6)

The computer-implemented method of claim 6, wherein the hot block and the cold block are of equal size, wherein after swapping the hot target and the cold target, the cold block begins where the hot block initially was located and the hot block begins where the cold block initially was located.

### Claim 8 (depends on 1)

The computer-implemented method of claim 1, wherein the branching instruction is determined to be more likely to proceed to the hot target than to the cold target at execution based on an analysis of trace indexes of C2 generated instructions over a plurality of iterations of the C2 generated instructions.

### Claim 9

A computer-implemented method, comprising:
identifying a branching instruction associated with:
a cold block starting with a cold target that the branching instruction flows to when a routing condition is a first one of true or false; and
a hot block located before the branching instruction in an instruction cache that starts at a hot target that flows to a subsequent instruction and that the branching instruction jumps to when the routing condition is a second one of true or false, wherein, based on historical data, the branching instruction is more likely to proceed to the hot target than to the cold target at execution;
inserting a space between the branching instruction and the cold target;
inserting a duplicate hot block and a jump instruction in the space, wherein the duplicate hot block flows to the jump instruction and the jump instruction jumps to the subsequent instruction; and
reversing the routing condition in the branching instruction to flow to the duplicate hot block when the routing condition is the second one of true or false and to jump to the cold target when the routing condition is the first one of true or false.

### Claim 10 (depends on 9)

The computer-implemented method of claim 9, further comprising after inserting the duplicate hot block and the jump instruction and reversing the routing condition:
executing instructions held in the instruction cache;
continuously monitoring execution of the instructions held in the instruction cache;
in response to determining that the branching instruction is more likely to proceed to the cold target than the hot target:
reclassifying the cold target as a new hot target;
reclassifying the hot target as a new cold target;
removing the duplicate hot block and the jump condition; and
reversing the routing condition.

### Claim 11 (depends on 9)

The computer-implemented method of claim 9, wherein identifying the branching instruction further comprises determining that a difference in likelihood of proceeding to the hot target than to the cold target exceeds a user defined threshold.

### Claim 12 (depends on 9)

The computer-implemented method of claim 9, wherein duplicating the hot target includes duplicating a plurality of instructions including the hot target and instructions located between the hot target and the subsequent instruction.

### Claim 13 (depends on 9)

The computer-implemented method of claim 9, wherein the branching instruction is determined to be more likely to proceed to the hot target than to the cold target at execution based on an analysis of trace indexes of C2-generated instructions.

### Claim 14

A computer-implemented method, comprising:
profiling branching instructions in an instruction cache to identify likelihoods of proceeding to a plurality of targets from the branching instructions;
identifying a hot path in the instruction cache based on the identified likelihoods; and
rearranging the plurality of targets relative to one another and associated branching instructions so that a first branching instruction that has a higher likelihood of proceeding to a first hot target than to a first cold target and that previously flowed to the first cold target and jumped to the first hot target instead flows to the first hot target and jumps to the first cold target.

### Claim 15 (depends on 14)

The computer-implemented method of claim 14, wherein rearranging the plurality of targets is performed just in time for execution of instructions in the instruction cache, wherein a second branching instruction that flows to a second cold target and jumps to a second hot target remains unaffected by the rearranging so that the second branching instruction that flows to the second cold target and jumps to the second hot target based on the second branching instruction having a lower priority below a cutoff threshold for just in time execution.

### Claim 16 (depends on 15)

The computer-implemented method of claim 15, wherein the first branching instruction has a higher priority for rearrangement than the second branching instruction based on a greater likelihood of the first branching instruction proceeding to the first hot target than the second branching instruction proceeding to the second hot target.

### Claim 17 (depends on 15)

The computer-implemented method of claim 15, wherein the first branching instruction has a higher priority for rearrangement than the second branching instruction based on the first branching instruction occurring earlier in the instruction cache than the second branching instruction.

### Claim 18 (depends on 14)

The computer-implemented method of claim 14, further comprising after rearranging the plurality of targets relative to one another:
executing instructions held in the instruction cache;
continuously monitoring execution of the instructions held in the instruction cache;
in response to determining that the hot path has changed:
re-profiling the branching instructions in an instruction cache to identify updated likelihoods of proceeding to the plurality of targets from the branching instructions; and
rearranging the plurality of targets relative to one another and the associated branching instructions so that the first branching instruction that has a higher updated likelihood of proceeding to a first updated hot target than to a first updated cold target and that previously flowed to the first updated cold target and jumped to the first updated hot target instead flows to the first updated hot target and jumps to the first updated cold target.

### Claim 19 (depends on 14)

The computer-implemented method of claim 14, wherein the first hot target is initially located after the first cold target in the instruction cache, wherein rearranging the plurality of targets relative to one another and the associated branching instructions further comprises:
swapping an order of the first cold target and the first hot target in the instruction cache; and
reversing a routing condition of the first branching instruction to jump to the first cold target and flow to the first hot target.

### Claim 20 (depends on 19)

The computer-implemented method of claim 19, in response to determining that the first cold target flows to the first hot target at execution, duplicating the first hot target in the instruction cache after the swapped first cold target.

### Claim 21 (depends on 14)

The computer-implemented method of claim 14, wherein the first hot block is initially located before the first branching instruction in the instruction cache and flows to a subsequent instruction that flows to the first branching instruction, and wherein rearranging the plurality of targets relative to one another and the associated branching instructions further comprises:
inserting a space in the instruction cache between the first branching instruction and the first cold target;
inserting a duplicate first hot block, including a duplicate first hot target, and a jump instruction in the space, wherein the duplicate first hot block flows to the jump instruction and the jump instruction jumps to the subsequent instruction; and
reversing a routing condition in the first branching instruction to flow to the duplicate first hot target and to jump to the first cold target.

### Claim 22

A system, comprising:
a processor, including an instruction cache;
a memory including instructions that when executed by the processor perform an operation comprising:
profiling branching instructions in the instruction cache to identify likelihoods of proceeding to a plurality of targets from the branching instructions;
identifying a hot path in the instruction cache based on the identified likelihoods; and
rearranging the plurality of targets relative to one another and associated branching instructions so that a first branching instruction that has a higher likelihood of proceeding to a first hot target than to a first cold target and that previously flowed to the first cold target and jumped to the first hot target instead flows to the first hot target and jumps to the first cold target.

### Claim 23 (depends on 22)

The system of claim 22, wherein the first hot target is initially located after the first cold target in the instruction cache, wherein rearranging the plurality of targets relative to one another and the associated branching instructions further comprises:
swapping an order of the first cold target and the first hot target in the instruction cache; and
reversing a routing condition of the first branching instruction to jump to the first cold target and flow to the first hot target.

### Claim 24 (depends on 22)

The system of claim 22, wherein the first hot target is initially located before the first branching instruction in the instruction cache and flows to a subsequent instruction that flows to the first branching instruction, and wherein rearranging the plurality of targets relative to one another and the associated branching instructions further comprises:
inserting a space in the instruction cache between the first branching instruction and the first cold target;
inserting a duplicate first hot block, including a duplicate first hot target, and a jump instruction in the space, wherein the duplicate first hot block flows to the jump instruction and the jump instruction jumps to the subsequent instruction; and
reversing a routing condition in the first branching instruction to flow to the duplicate first hot target and to jump to the first cold target.

### Claim 25

A computer-readable storage medium having computer-readable program code embodied therewith, the computer-readable program code executable by one or more computer processors to:
profile branching instructions in an instruction cache to identify likelihoods of proceeding to a plurality of targets from the branching instructions;
identify a hot path in the instruction cache based on the identified likelihoods; and
rearrange the plurality of targets relative to one another and associated branching instructions so that a first branching instruction that has a higher likelihood of proceeding to a first hot target than to a first cold target and that previously flowed to the first cold target and jumped to the first hot target instead flows to the first hot target and jumps to the first cold target.
