# US 2022/0283927 A1 · Compound conditional reordering for faster short-circuiting

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

- Number: US 2022/0283927 A1
- Document ID: US20220283927A1
- Status: Published application
- Kind: A1
- Application number: 17/663,303
- Filed: 2022-05-13
- Published: 2022-09-08
- Earliest claimed: 2018-04-13
- Assignees: Microsoft Technology Licensing, LLC
- Applicants: Microsoft Technology Licensing, LLC
- Inventors: Amit Jayant SABNE; Eric Avi BRUMER
- Web page: https://patentgrep.com/patent/US20220283927A1

## CPC

- G06F 8/4441: {Reducing the execution time required by the program code}
- G06F 11/3616: {using software metrics}
- G06F 8/43: {Checking; Contextual analysis}
- G06F 8/443: {Optimisation}
- G06F 9/30058: {Conditional branch instructions}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A computing device is provided, including a processor configured to receive source code at a compiler. The source code may include at least one compound conditional having a plurality of conditions. For each condition of the plurality of conditions, the source code may further include a respective code block including instructions to evaluate the condition. For each ordering of a plurality of orderings of the plurality of conditions, the processor may determine that the ordering satisfies one or more legality constraints. For each ordering of the plurality of orderings that satisfy the one or more legality constraints, the processor may determine a respective estimated computational cost for that ordering. The processor may reorder the plurality of conditions to have an ordering that has a lowest estimated computational cost of the plurality of orderings that satisfy the one or more legality constraints.

## Claims

### Claim 1

A computing device comprising a processor configured to:
during an execution of a compiler:
receive source code at the compiler, wherein the source code includes:
at least one compound conditional having a plurality of conditions configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code are to be executed as part of the execution of the assembly code,
wherein each condition of the plurality of conditions includes a code block that includes one or more instructions to evaluate the condition as part of execution of the assembly code;
determine that two or more orderings of a plurality of orderings of the plurality of conditions of the compound conditional satisfy one or more legality constraints on a syntactic structure of the one or more instructions of each of the plurality of conditions, and that at least one ordering of the plurality of orderings does not satisfy the one or more legality constraints;
for each ordering of the plurality of orderings that satisfy the one or more legality constraints, during the execution of the compiler and subsequently to determining that the ordering satisfies the one or more legality constraints, determine a respective estimated computational cost for that ordering without determining at least one respective computational cost for the at least one ordering that does not satisfy the one or more legality constraints;
reorder the plurality of conditions to have an ordering that has a lowest estimated computational cost of the plurality of orderings that satisfy the one or more legality constraints; and
compile the source code with the reordered plurality of conditions into the assembly code.

### Claim 2 (depends on 1)

The computing device of claim 1, wherein the source code further includes:
a first branch code block including one or more first branch evaluation instructions configured to be executed when the plurality of conditions are true; and
a second branch code block including one or more second branch evaluation instructions configured to be executed when at least one condition of the plurality of conditions is false.

### Claim 3 (depends on 2)

The computing device of claim 2, wherein the one or more legality constraints include a constraint that the source code includes one first branch code block and one second branch code block.

### Claim 4 (depends on 1)

The computing device of claim 1, wherein the one or more legality constraints include a constraint that the respective code block of each condition includes an instruction to proceed to a common target code block.

### Claim 5 (depends on 4)

The computing device of claim 4, wherein the one or more legality constraints include a constraint that a portion of the source code that follows a last code block of the respective code blocks of the plurality of conditions and that precedes the common target code block has one entry point and one exit point.

### Claim 6 (depends on 1)

The computing device of claim 1, wherein the one or more legality constraints include a constraint that no instruction calls an undefined variable.

### Claim 7 (depends on 1)

The computing device of claim 1, wherein each code block is a basic block.

### Claim 8 (depends on 1)

The computing device of claim 1, wherein at least one code block includes a plurality of basic blocks.

### Claim 9 (depends on 1)

The computing device of claim 1, wherein the processor is configured to determine the respective estimated computational cost for each ordering at least in part by summing estimated cost scores assigned to instruction types for each instruction included in the ordering.

### Claim 10 (depends on 9)

The computing device of claim 9,
wherein each of the plurality of instruction types is a respective type of operation, and where each type of operation has an associated estimated integer cost and an estimated floating-point cost, the estimated integer cost being an estimated cost score of the type of operation when performed using integer computation, and the estimated floating-point cost being an estimated cost score of the type of operation when performed using floating point computation; and
wherein the types of operations include addition, subtraction, comparison, negation, division, remainder, AND, OR, XOR, minimum, maximum, load, and/or store.

### Claim 11

A method performed by a processor of a computing device, the method comprising:
during an execution of a compiler:
receiving source code at the compiler, wherein the source code includes:
at least one compound conditional having a plurality of conditions configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code are to be executed as part of the execution of the assembly code,
wherein each condition of the plurality of conditions includes a code block that includes one or more instructions to evaluate the condition as part of execution of the assembly code;
determining that two or more orderings of a plurality of orderings of the plurality of conditions included in the compound conditional satisfy one or more legality constraints on a syntactic structure of the one or more instructions of each of the plurality of conditions, and that at least one ordering of the plurality of orderings does not satisfy the one or more legality constraints;
for each ordering of the plurality of orderings that satisfy the one or more legality constraints, during the execution of the compiler and subsequently to determining that the ordering satisfies the one or more legality constraints, determining a respective estimated computational cost for that ordering without determining at least one respective computational cost for the at least one ordering that does not satisfy the one or more legality constraints,
reordering the plurality of conditions to have an ordering that has a lowest estimated computational cost of the plurality of orderings that satisfy the one or more legality constraints; and
compiling the source code with the reordered plurality of conditions into the assembly code.

### Claim 12 (depends on 11)

The method of claim 11, wherein the source code further includes:
a first branch code block including one or more first branch evaluation instructions configured to be executed when the plurality of conditions are true; and
a second branch code block including one or more second branch evaluation instructions configured to be executed when at least one condition of the plurality of conditions is false.

### Claim 13 (depends on 12)

The method of claim 12, wherein the one or more legality constraints include a constraint that the source code includes one first branch code block and one second branch code block.

### Claim 14 (depends on 11)

The method of claim 11, wherein the one or more legality constraints include a constraint that the respective code block of each condition includes an instruction to proceed to a common target code block.

### Claim 15 (depends on 11)

The method of claim 11, wherein the one or more legality constraints include a constraint that a portion of the source code that follows a last code block of the respective code blocks of the plurality of conditions and that precedes the common target code block has one entry point and one exit point.

### Claim 16 (depends on 11)

The method of claim 11, wherein the one or more legality constraints include a constraint that no instruction calls an undefined variable.

### Claim 17 (depends on 11)

The method of claim 11, wherein each code block is a basic block.

### Claim 18 (depends on 11)

The method of claim 11, wherein at least one code block includes a plurality of basic blocks.

### Claim 19 (depends on 11)

The method of claim 11, wherein determining the respective estimated computational cost for each ordering includes:
assigning an estimated cost score to each instruction included in the ordering; and
summing the respective estimated cost scores assigned to each instruction.

### Claim 20

A computing device comprising a processor configured to:
during an execution of a compiler:
receive source code at the compiler, wherein the source code includes a plurality of code blocks that are included in a compound conditional and are configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code are to be executed as part of the execution of the assembly code;
determine that two or more orderings of a plurality of orderings of the plurality of code blocks of the compound conditional satisfy one or more legality constraints on a syntactic structure of one or more instructions of each of the plurality of code blocks, and that at least one ordering of the plurality of orderings does not satisfy the one or more legality constraints;
for each ordering of the plurality of orderings that satisfy the one or more legality constraints, during the execution of the compiler and subsequently to determining that the ordering satisfies the one or more legality constraints, determine a respective estimated computational cost for that ordering without determining at least one respective computational cost for the at least one ordering that does not satisfy the one or more legality constraints,
wherein the at least one respective computational cost for each ordering of the plurality of orderings that satisfy the one or more legality constraints is determined at least in part by determining estimated cost scores assigned to instruction types for each instruction included in the ordering, wherein the types of operations include addition, subtraction, comparison, negation, division, remainder, AND, OR, XOR, minimum, maximum, load, and/or store;
reorder the plurality of code blocks to have an ordering that has a lowest estimated computational cost of the plurality of orderings that satisfy the one or more legality constraints; and
compile the source code with the reordered plurality of conditions into the assembly code.
