Repository navigation
Conversation
|
Azure Pipelines: Successfully started running 8 pipeline(s). 8 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
d93ee33 to
e17cc2d
Compare
Produce the "x +/- compare" shape that lowering turns into adc/sbb/cinc in more places: - If-conversion turns SELECT(cond, x +/- 1, x) and SELECT(cond, k + 1, k) into "x +/- cond" and "k + cond" on all targets when cond is a compare that lowering can consume as a carry (== 0, != 0 and unsigned compares). Inside loops, if-conversion is now allowed when the result is such arithmetic instead of a SELECT, so "if (a[i] < p) count++" becomes "cmp; adc" instead of a branch. - Operands without side effects or memory reads may be evaluated unconditionally even when the condition has ordering side effects. - If-converted values stored to a temp whose only use adds or subtracts it are forwarded into that use, e.g. "num + (r ? 0 : -1)" becomes "cmp r, 1; sbb num, 0" on x64. - Value numbering can now tell when a value is always 0 or 1: compares, 0/1 constants, AND/OR/XOR and casts of such values, and phis of them. VN-based folding uses this to fold "x != 0" to "x" and "x == 0" to "x ^ 1". Values loaded from memory are not affected, so bools holding other non-zero values are still handled as ECMA requires.
e17cc2d to
97d168d
Compare
|
There's also #134039 which might overlap and or benefit from the same (and I have my own variant of the optimization too, which I've not looked at in a bit but which I just rebased on dotnet/main and had AI do a fresh pass over: https://github.com/tannergooding/runtime/tree/tannergooding-jit-adc-sbb-carry-pattern). This is a general pattern and setup that could be broadly impactful with the right overall handling/setup and might warrant some cross scenario measurements and comparisons |
|
Sounds good. We could get opus/fable type of model to go over these three/four overlapping PRs and gather valuable parts and supersede. I asked the model to lean towards fewer diffs. In its footnotes, it said something like "there are more phases/places in JIT where this pattern could be applied". |
Produce the "x +/- compare" shape that lowering turns into adc/sbb/cinc
in more places:
k) into "x +/- cond" and "k + cond" on all targets when cond is a
compare that lowering can consume as a carry (== 0, != 0 and unsigned
compares). Inside loops, if-conversion is now allowed when the result
is such arithmetic instead of a SELECT, so "if (a[i] < p) count++"
becomes "cmp; adc" instead of a branch.
unconditionally even when the condition has ordering side effects.
it are forwarded into that use, e.g. "num + (r ? 0 : -1)" becomes
"cmp r, 1; sbb num, 0" on x64.
0/1 constants, AND/OR/XOR and casts of such values, and phis of them.
VN-based folding uses this to fold "x != 0" to "x" and "x == 0" to
"x ^ 1". Values loaded from memory are not affected, so bools holding
other non-zero values are still handled as ECMA requires.
Note: #135678's commit is included here.