Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gc2stack pass #2750

Merged
merged 2 commits into from
Jun 20, 2018
Merged

Fix gc2stack pass #2750

merged 2 commits into from
Jun 20, 2018

Conversation

Hardcode84
Copy link
Contributor

No description provided.

@Hardcode84 Hardcode84 changed the title Fix gc2stack pass WIP: Fix gc2stack pass Jun 17, 2018
@Hardcode84
Copy link
Contributor Author

Hardcode84 commented Jun 17, 2018

druntime-test-exceptions/invalid_memory_operation.d runs code

struct S
{
    ~this()
    {
        new int;
    }
}

void main()
{
    new S;
}

and expects it will crash with InvalidMemoryOperationError.
This obviously won't happen after this optimization as new int is moved to stack and optimized out.

@dnadlinger
Copy link
Member

Breaking that test is fine imho – iirc it was only supposed to test that there is no infinite recursion caused by the EH code or something along those lines.

@Hardcode84
Copy link
Contributor Author

Fix for invalid_memory_operation test: ldc-developers/druntime#145

@kinke
Copy link
Member

kinke commented Jun 17, 2018

@Hardcode84: How did you manage to run those tests with enabled optimizations? Do you set the DFLAGS env variable manually?

@Hardcode84
Copy link
Contributor Author

@kinke just run ctest from git bash terminal.

@kinke
Copy link
Member

kinke commented Jun 17, 2018

Well AFAICT that can't be without some special setup from your side, I mean this test hasn't been failing for CI and I've never seen it fail myself, plus I don't see any -O in the corresponding Makefile.

@Hardcode84
Copy link
Contributor Author

@kinke They passed because gc2stack pass was completely broken for (probably) very long time.

@kinke
Copy link
Member

kinke commented Jun 17, 2018

Nope they passed because they are never run with -O and so no gc2stack.

@Hardcode84
Copy link
Contributor Author

If I revert submodule update from this PR, they will fail on CI because of gc2stack as well

@kinke
Copy link
Member

kinke commented Jun 17, 2018

[I've been on vacation this week, so I'm not fully up-to-date.]

@Hardcode84
Copy link
Contributor Author

@kinke
Copy link
Member

kinke commented Jun 17, 2018

Alright, so the druntime standalone tests are (only) run with -O -release, and GC2Stack was really badly broken, only working for 1 of your new testcases (foo3). Thanks for the fix!

I'm planning on releasing 1.10 final these days; how's your pipeline looking, any more patches to come in? :)

@Hardcode84
Copy link
Contributor Author

Hardcode84 commented Jun 17, 2018

I'm not tied to releases and this is somewhat dangerous fix for final version. There can be cases where it will incorrectly optimize which I didn't foresee.

@Hardcode84 Hardcode84 changed the title WIP: Fix gc2stack pass Fix gc2stack pass Jun 17, 2018
@Hardcode84
Copy link
Contributor Author

BTW, I don't see release branch, do we release from master now?

->getType();

// Value *ti = llvm::MetadataAsValue::get(node->getContext(),
Copy link
Member

Choose a reason for hiding this comment

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

No point in keeping this around, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@Hardcode84
Copy link
Contributor Author

@kinke You can merge this if you think it should go into 1.10 release, but I'm fine if it go to next release.

@kinke
Copy link
Member

kinke commented Jun 18, 2018

I'd have included it if it was just me, as it seems to make GC2Stack work as intended (but yeah, that might cause issues indeed). The next beta is only a couple of weeks away I guess, so let's wait a little bit with this one.

@Hardcode84
Copy link
Contributor Author

Hardcode84 commented Jun 18, 2018

Fun fact: there is also SimplifyDRuntimeCalls pass which should remove gc allocations completely if their result isn't used and break invalid_memory_operation test even if -disable-gc2stack specified.
But it didn't so it is probably also broken.

if (!ti || ti->stripPointerCasts() != ti_global) {
auto md = llvm::dyn_cast<llvm::ValueAsMetadata>(
node->getOperand(TD_TypeInfo).get());
if (md == nullptr || md->getValue() != ti_global) {
Copy link
Member

Choose a reason for hiding this comment

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

No more stripPointerCasts()?

Copy link
Contributor Author

@Hardcode84 Hardcode84 Jun 19, 2018

Choose a reason for hiding this comment

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

I can add it but I'm not sure how to trigger it.

Some context: first metadata operand is GlobalVariable for Typinfo object and we compare it with GlobalVariable typeinfo passed as parameter to allocation function.

Copy link
Member

Choose a reason for hiding this comment

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

[The TypeInfo globals used to be pointers to anonymous IR struct types IIRC; I changed them to the final TypeInfo subtypes (TypeInfo_Struct, TypeInfo_Class etc.).] So if the param is a TypeInfo* base class reference, the casts are better stripped for the comparison; they are already stripped for ti_global.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, thanks.

@Hardcode84
Copy link
Contributor Author

1.10 is out, so it can be merged, I think

@dnadlinger dnadlinger merged commit fdf6ce8 into ldc-developers:master Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants