You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Jit: Bounds checks are not removed in some inlined functions #32414
In the "Caller" case the local address visitor folds up the initial check into a LCL_FLD which value numbers differently than the IND(ADD(...)) in the bounds check that amounts to the same thing, so we fail to optimize.
In the base case, both trees are left as IND trees, because the base of the indirections is an implict by-ref argument, and CSE/optimization kicks in.
So presumably if we followed up on the following TODO-ADDR we'd see similar codegen in the "Caller" case.
if (varDsc->lvPromoted || varDsc->lvIsStructField || m_compiler->lvaIsImplicitByRefLocal(val.LclNum()))
{
// TODO-ADDR: For now we ignore promoted and "implict by ref" variables,
// they require additional changes in subsequent phases.
return;
Going to mark this as future as I don't know how common this sort of thing is and changes to implicit byref handling are likely to be somewhat involved.
Actually I probably have that backwards -- if we handle byrefs as in the above we'll fail to optimize both cases. The root issue is that a LCL_FLD and "equivalent" IR via IND and such won't value number the same; we can get the latter if the address math is spread over statements and/or we hit limitations like the implicit byref above.
Activity
EgorBo commentedon Feb 16, 2020
I don't see any redundant bound checks in
BeginsWith0Callerin master, how old is your branch?Thealexbarney commentedon Feb 16, 2020
About a week old. The checks are still there in your code.
benaadams commentedon Feb 16, 2020
@EgorBo you aren't output the prologue and epilogue ;)
Misses out this bit
EgorBo commentedon Feb 16, 2020
haha, indeed :)
Thealexbarney commentedon Feb 16, 2020
Edit: The comment this was replying to was removed.
I'm surprised that pattern isn't optimized away.
AndyAyersMS commentedon Feb 19, 2020
@Thealexbarney thanks for the report.
In the "Caller" case the local address visitor folds up the initial check into a LCL_FLD which value numbers differently than the IND(ADD(...)) in the bounds check that amounts to the same thing, so we fail to optimize.
In the base case, both trees are left as IND trees, because the base of the indirections is an implict by-ref argument, and CSE/optimization kicks in.
So presumably if we followed up on the following TODO-ADDR we'd see similar codegen in the "Caller" case.
runtime/src/coreclr/src/jit/lclmorph.cpp
Lines 797 to 809 in e771456
Going to mark this as future as I don't know how common this sort of thing is and changes to implicit byref handling are likely to be somewhat involved.
AndyAyersMS commentedon Feb 19, 2020
Actually I probably have that backwards -- if we handle byrefs as in the above we'll fail to optimize both cases. The root issue is that a LCL_FLD and "equivalent" IR via IND and such won't value number the same; we can get the latter if the address math is spread over statements and/or we hit limitations like the implicit byref above.
Ideally
[000043]and[000055]have the same VNSo perhaps would be nice to fix this in value numbering?
EgorBo commentedon May 5, 2024
Current codegen for
BeginsWith0Caller: