This is an archive of the discontinued LLVM Phabricator instance.

[AliasSetTracker] Actually delete instructions from the AliasSetTracker.
AbandonedPublic

Authored by asbirlea on Oct 26 2018, 5:21 PM.

Details

Reviewers
reames
mkazantsev
Summary

When instructions are added, it's not the instruction being added, but its pointer.
The only actual instructions that are added are the unknown ones.
Trying to make some sense of this by actually removing pointers when an instruction is removed.
Oddly, this patch doesn't break anything.

Sending the changes to perhaps makes some sense on the purpose of the removeValue() function.
These changes are incomplete, given the special handling of arguments for callsites when adding an instruction,
but it's deleting more than before...

Diff Detail

Event Timeline

asbirlea created this revision.Oct 26 2018, 5:21 PM
MaskRay added inline comments.
lib/Analysis/AliasSetTracker.cpp
557

deleteValue((Value *)I);

asbirlea updated this revision to Diff 171389.Oct 26 2018, 9:31 PM

clang-format. Thank you!

asbirlea marked an inline comment as done.Oct 26 2018, 9:31 PM

Hm, can I ask what problem you were originally trying to solve? From a quick search, this code is only invoked through the value handle deleted callback. In which case, the value being deleted is the pointer itself, not the original using instruction.

This feels like possibly a solution in search of a problem?

lib/Analysis/AliasSetTracker.cpp
555

I get what you're going for, but this is not enough. Some instructions (calls) can map to multiple memory locations. You're also not removing unknown instructions.

lib/Transforms/Scalar/LICM.cpp
318

It took me a second to see why this was necessary. This change actually worries me a bit since it implies we may have other cases which need updated after your change.

This feels like possibly a solution in search of a problem?

One potentially problematic scenario in the current code would be if someone recursively deleted a user instruction inside an AST iteration loop. I think that would delete the pointer value, and if that was the last value in a given AS, invalidate the iteration.

What I'm not entirely clear about is why we care about deleting empty AliasSets from the AST eagerly? That's probably a deeper design question though.

I agree with all your points! Thank you for following up.

The issue is, we have this "deleteValue" which, AFAICT, is only called from LICM, only when removing dead instructions.

But, the AST has pointers + unknown instructions. So calling deleteValue(I) never removes pointers, only the unknown instructions.
I was attempting to see what happens if I do make it remove the pointers, when given an Instruction. But that's not nearly enough or, in my mind, correct.

  1. It's not enough, because when adding an instruction we may add more than a pointer (such as arguments added for a CallSite), just like you said.
  2. It's not correct, because when removing an instruction with pointer Ptr, we're removing Ptr from the set, even if there may be other instructions modifying that Ptr.

Hence my surprise that this patch is not breaking anything :)

Now, when actually removing pointers in LICM we're now invalidating the iterator over alias sets, hence the change you noticed that's worrying. I cannot see other cases where this would happen.
Before, we were not removing anything, because that part is doing promotion, and we're never promoting unknown instructions, hence the calls to deleteValue in that part of LICM are pretty much no-ops.

Broader question is, as you very well put it: why are we removing things? Or better phrased: why are we attempting to remove things?
If we really care about removed instructions to reflect in the AST, this patch needs a rewrite.
If we don't care about removed instructions, then the "deleteValue()" API and its uses can *mostly* all go away.

(I can see one potential use case: call deleteValue(I) when sinking/hoisting if the instruction is dead, which may make an alias set free of unknown instructions and hence promotable; but then deleteValue could be renamed deleteUnknownInstruction and it would not be called anywhere in the promotion section, so we wouldn't worry about potential iterator invalidations.)

asbirlea added inline comments.Oct 29 2018, 4:24 PM
lib/Analysis/AliasSetTracker.cpp
555

You're right about the unknown instructions. I had thought that at least we're removing those, but they're never added to the PointerMap.
So, yeah, I don't understand the purpose of deleteValue() at all.
AFAICT, all these calls and the API can be dropped.

Is it possible to write a test on that?

lib/Analysis/AliasSetTracker.cpp
554

Does it make sense to name it deleteInstruction and remove the cast below?

Let me re-purpose this patch:
Is there a point to having deleteValue()?
Is there a point to having the ref count (addRef, dropRef) for alias sets?

AFAICT these are incomplete and not used.

Unfortunately I am not familiar enough with AliasSetTracker to answer that question. We should maybe wait for @reames to clarify it.

Let me re-purpose this patch:
Is there a point to having deleteValue()?
Is there a point to having the ref count (addRef, dropRef) for alias sets?

AFAICT these are incomplete and not used.

Any update here? Or should this just be a separate patch?

asbirlea abandoned this revision.Jan 28 2019, 3:09 PM

I'm going to drop this for now.