Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix ArrayStack's call to default constructor for <T>.#21624

Merged
sandreenko merged 4 commits into
dotnet:masterfrom
sandreenko:arrayStackFix
Dec 23, 2018
Merged

Fix ArrayStack's call to default constructor for <T>.#21624
sandreenko merged 4 commits into
dotnet:masterfrom
sandreenko:arrayStackFix

Conversation

@sandreenko
Copy link
Copy Markdown

The first commit add IsEmpty(), the second adds BottomRef(), the third fixes the old issue that template argument for ArrayStack had 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

@mikedn
Copy link
Copy Markdown

mikedn commented Dec 21, 2018

I think you also requested this change, could you please review it?

Yes, I wanted to do this for a while now but somehow I kept postponing it. Tank you!

Comment thread src/jit/arraystack.h Outdated
Comment thread src/jit/arraystack.h Outdated
Comment thread src/jit/arraystack.h Outdated
Comment thread src/jit/arraystack.h Outdated
Comment thread src/jit/arraystack.h
T* data;
// initial allocation
T builtinData[builtinSize];
char builtinData[builtinSize * sizeof(T)];
Copy link
Copy Markdown

@mikedn mikedn Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😄

@mikedn
Copy link
Copy Markdown

mikedn commented Dec 21, 2018

Hold on a bit, PIN seems to show a significant regression on this change. Odd.

@mikedn
Copy link
Copy Markdown

mikedn commented Dec 21, 2018

Hmm, false alarm. The regression is small, only 0.08%. Still, I was expecting a small improvement, not a small regression.

@mikedn
Copy link
Copy Markdown

mikedn commented Dec 21, 2018

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:

  • a lot of these ArrayStack objects are ArrayStack<GenTree*> or similar, in this case no initialization was performed to begin with. It's an array of primitive types, not an array of class objects.
  • something, most like the builtin array reinterpretation, triggers VC++'s /GS checks. I doubt that those a significant impact but here and there they also seem to cause other issues (failure inline some functions apparently).

So, anyone knows a way to declare an array of T that doesn't result in initialization and doesn't require reinterpretation?

@sandreenko
Copy link
Copy Markdown
Author

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:

union S
{
  char builtinDataCache[builtinSize * sizeof(T)];
  T* builtinData;
};

but did not measure pin, I think it looks too bad even if we get a tiny perf win.

@mikedn
Copy link
Copy Markdown

mikedn commented Dec 21, 2018

I was playing with unions like:

Hmm, I tried a different version - an array of unions of char and T. /GS still doesn't like it.

I think it looks too bad even if we get a tiny perf win.

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.

@sandreenko
Copy link
Copy Markdown
Author

PR was updated with small fixes.

@sandreenko sandreenko merged commit 47c5949 into dotnet:master Dec 23, 2018
@sandreenko sandreenko deleted the arrayStackFix branch December 23, 2018 06:42
Comment thread src/jit/arraystack.h
}

// return a reference to the i'th from the bottom
T BottomRef(int indx)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will use this function in my next PR and fix it there.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…#21624)

* Add ArrayStack::Empty

* Add ArrayStack::BottomRef

* Delete unused `ReverseTop`.

* do not use default constructor.


Commit migrated from dotnet/coreclr@47c5949
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants