Skip to content

Evaluate both lifted arithmetic operands before propagating null - #620

Merged
dadhi merged 1 commit into
dadhi:masterfrom
jogibear9988:fix/lifted-operand-evaluation-standalone
Nov 10, 2026
Merged

dadhi merged 1 commit into
dadhi:masterfrom
jogibear9988:fix/lifted-operand-evaluation-standalone

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Lifted arithmetic can skip the right operand when the left is null, losing side effects and exceptions. Evaluate and cache the right operand first, then perform nullable checks. Reuse the existing nullable/value locals when consuming the cache.

Eight lifted arithmetic/bitwise operators; null and non-null combinations; exactly-once evaluation order and right-operand exceptions. Regressions use strict FEC compilation for both Standard and LightExpression.

Validation

Release solution build: zero warnings/errors.

Runtime TestX groups Legacy tests
.NET 10 445 passed 1,756 passed
.NET 8 445 passed 1,755 passed
.NET Framework 4.7.2 424 passed 1,639 passed

Measurements

Current master f1d2fb33 → this change, Release, Windows ARM64, .NET 8.0.28 / 10.0.9. Compilation uses prebuilt trees; runtime measures invocation through the same wrapper. Two fresh process rounds with reversed load order, seven samples per round, about 30 ms calibration, one logical CPU and tiered compilation disabled. Tables use the median of the two per-round medians.

The controls below produce correct results on master for their measured inputs. Newly supported trees have no valid before/after execution comparison because master rejects them, produces incorrect results or emits invalid IL. Timings include machine and JIT/code-placement variation; the unchanged add control helps show that variation. These observations do not prove universal performance neutrality.

net8.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 1412.8 → 1390.5 2.5 → 2.4 872.0 → 872.0 0.0 → 0.0
Standard / nullable_add 3729.5 → 3838.2 6.6 → 8.2 1928.0 → 1928.0 0.0 → 0.0
Standard / nullable_add_null 3589.1 → 3573.0 2.8 → 2.8 1928.0 → 1928.0 0.0 → 0.0
Light / add_control 1212.2 → 1325.9 2.3 → 2.4 872.0 → 872.0 0.0 → 0.0
Light / nullable_add 3400.6 → 2981.5 4.2 → 2.9 1928.0 → 1928.0 0.0 → 0.0
Light / nullable_add_null 2706.2 → 2750.2 2.4 → 2.5 1928.0 → 1928.0 0.0 → 0.0
net10.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 5485.8 → 5443.4 2.5 → 2.6 872.0 → 872.0 0.0 → 0.0
Standard / nullable_add 11979.1 → 13153.8 2.6 → 2.6 1928.0 → 1928.0 0.0 → 0.0
Standard / nullable_add_null 9784.4 → 9937.3 2.5 → 2.7 1928.0 → 1928.0 0.0 → 0.0
Light / add_control 2632.9 → 2529.8 2.0 → 2.0 872.0 → 872.0 0.0 → 0.0
Light / nullable_add 7643.5 → 8155.2 2.3 → 2.3 1928.0 → 1928.0 0.0 → 0.0
Light / nullable_add_null 8573.4 → 8029.7 2.8 → 3.0 1928.0 → 1928.0 0.0 → 0.0

Emitted IL differs in these measured workloads: nullable_add, nullable_add_null.
No measured allocation increase above 0.1 B/op in these controls.

Lifted arithmetic can skip the right operand when the left is null, losing side effects and exceptions. Evaluate and cache the right operand first, then perform nullable checks. Reuse the existing nullable/value locals when consuming the cache.
@dadhi
dadhi merged commit ce28e2b into dadhi:master Nov 10, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/lifted-operand-evaluation-standalone branch November 10, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants