Fix ArrayStack's call to default constructor for <T>.#21624
Conversation
Yes, I wanted to do this for a while now but somehow I kept postponing it. Tank you! |
| T* data; | ||
| // initial allocation | ||
| T builtinData[builtinSize]; | ||
| char builtinData[builtinSize * sizeof(T)]; |
There was a problem hiding this comment.
FWIW this is not the ideal solution because we're losing T's alignment. But I'm not aware of anything in the JIT that requires larger than pointer alignment and the array is pointer aligned due to the T* data; that precedes it.
P.S. And anyway I'm not sure what the ideal solution is anyway 😄
|
Hold on a bit, PIN seems to show a significant regression on this change. Odd. |
|
Hmm, false alarm. The regression is small, only 0.08%. Still, I was expecting a small improvement, not a small regression. |
|
Interesting situation. You'd think that removing the useless initialization of an 8 element array (plus whatever initialization is performed when dynamically allocating the array) would result in a perf win. But:
So, anyone knows a way to declare an array of T that doesn't result in initialization and doesn't require reinterpretation? |
I was playing with unions like: but did not measure pin, I think it looks too bad even if we get a tiny perf win. |
Hmm, I tried a different version - an array of unions of
Yep. Personally I'm fine with the 0.08% regression, considering that I can pull improvements from other places like rabbits from a hat 😄. It's just that I wasn't expecting this. |
dc3c89e to
6da4d88
Compare
|
PR was updated with small fixes. |
| } | ||
|
|
||
| // return a reference to the i'th from the bottom | ||
| T BottomRef(int indx) |
There was a problem hiding this comment.
@sandreenko This should have been T& 😁. Unfortunately I only noticed this now, when you merged and I saw a conflict with my own BottomRef in another PR.
There was a problem hiding this comment.
Thank you. I will use this function in my next PR and fix it there.
…#21624) * Add ArrayStack::Empty * Add ArrayStack::BottomRef * Delete unused `ReverseTop`. * do not use default constructor. Commit migrated from dotnet/coreclr@47c5949
The first commit add
IsEmpty(), the second addsBottomRef(), the third fixes the old issue that template argument forArrayStackhad to have a default constructor.I hit the last issue again in #21395 so decided to fix it.
@mikedn I think you also requested this change, could you please review it?
PTAL @dotnet/jit-contrib