This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Remove premature assert. PR46786
ClosedPublic

Authored by mkazantsev on Jul 22 2020, 12:43 AM.

Details

Summary

This assert was added to verify assumption that GEP's SCEV will be of pointer type,
basing on fact that it should be a SCEVAddExpr with (at least) last operand being
pointer. Two notes:

  • GEP's SCEV does not have to be a SCEVAddExpr after all simplifications;
  • In current state, GEP's SCEV does not have to have at least one pointer operands (all of them can become int during the transforms).

However, we might want to be at a point where it is true. We are currently removing
this assert and will try to enumerate the cases where "is pointer" notion might be
lost during the transforms. When all of them are fixed, we can return it.

Diff Detail

Event Timeline

mkazantsev created this revision.Jul 22 2020, 12:43 AM

I'm obviously okay with dropping the assert until it actually doesn't trigger.

(copying from https://bugs.llvm.org/show_bug.cgi?id=46786#c8)

The question is, is "is pointer" a sticky bit or not?
In IR, GEP takes a pointer and produces a pointer.
In SCEV, as we can see, that's not really so.

In IR, if it ask GetUnderlyingObject() about some GEP,
it will recurse into the base pointer somewhat and return something.

In SCEV, if i ask SCEV::getPointerBase() about getSCEV(same GEP),
it will only try to recurse as long as there is exactly a single pointer operand.
So if GEP's SCEV somehow got folded in a way that obscured the fact that it produces a pointer,
i think there's an issue.

So here, i would actually think the problem is that the fix in D82633
was too narrow. Instead of fixing SCEVAddExpr::getType(), SCEVNAryExpr::getType()
should have been fixed, i believe that would resolve the assertion in this report.

lebedev.ri accepted this revision.Jul 22 2020, 1:14 AM

FTR this patch was my plan forward anyways.

This revision is now accepted and ready to land.Jul 22 2020, 1:14 AM

I think we have some cases (related to mul) where "is pointer" notion can be lost. Maybe we can fix it. Let me try to construct some more examples of those.

Generally, the assert looks like we might have it, but first we should be certain that we ensure it is actually so. It might take some extensive work (I see some checks like "we do not work with pointer this or that" over the code).

Let me try to find more tests that fail this assert with educated guesses. Then I'll add them here, and then, when all of them are resolved, I'm fine with returning assert.

mkazantsev retitled this revision from [SCEV] Remove invalid assert. PR46786 to [SCEV] Remove premature assert. PR46786.Jul 22 2020, 1:34 AM
mkazantsev edited the summary of this revision. (Show Details)

I've updated commit message basing on our discussion. We want to be at a point when "is pointer" notion doesn't get lost. We are clearly not at this point now. We need to assess the amount of work we should do to get there, and construct more tests exercising different scenarios of this.

This revision was automatically updated to reflect the committed changes.