dotnet / dotnet/runtime

Extend JIT Cast Removal Pattern for Simple Ops

Open
#121,384 2 comments 1 reaction 2 assignees Assigned to @adamperlin View on GitHub
area-CodeGen-coreclr
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

#120980 brings new range assertions that allow casts on bitwise operations such as `and` to be eliminated in some cases since the range of the op can now be proven to be within bounds of the cast target. However, we have existing logic in [fgSimpleLowerCastOfSmpOp](https://github.com/dotnet/runtime/blob/09a4d35c12a0e3b82a5c675512c12ed64bfecc5b/src/coreclr/jit/flowgraph.cpp#L2752) which expects to match an outer cast and perform the optimization: `CAST(AND(CAST(x), CAST(y))) -> CAST(AND(x, y))`. This means that in some cases this match is now broken by the cast elimination in an earlier phase, and we still end up with two casts for both the operands, i.e. `AND(CAST(x), CAST(y))`. We should see if we can improve the logic here such that we can still optimize these cases down to only at most one cast.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.