This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Leverage inferred no-self-wrap flags to refine trip counts
AbandonedPublic

Authored by reames on Nov 18 2021, 12:48 PM.

Details

Summary

This is a follow on to D114176. It adds the missing piece to actually build a new expression for the LHS using the newly discovered flag information.

I need to add a few more tests, before this lands. In the meantime, a question for the reviewers: is the approach of removing nodes from UniqueSCEVs reasonable? This has some serious downsides (breaking equality), but the other option requires a ton of duplicated code. Anyone see any other ideas?

Diff Detail

Event Timeline

reames created this revision.Nov 18 2021, 12:48 PM
reames requested review of this revision.Nov 18 2021, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2021, 12:48 PM

I'm really uncomfortable with removing things from UniqueSCEVs. If I understood correctly, your motivation here is that getZeroExtendExpr will not try folds if it has already memoized that the fact that this expression doesn't fold. I think we'd be better off adding a parameter to skip that check for this use-site.

Though I'm generally starting to have doubts about the direction of the whole patch stack (starting D103991). I find this kind of after the fact fixup of SCEVs rather problematic. Just the additional nowrap flags inferred during zext/sext construction can already cause hard to understand "spooky action at a distance", and this takes things one step further. I didn't really appreciate that this is where this is going.

I'm really uncomfortable with removing things from UniqueSCEVs. If I understood correctly, your motivation here is that getZeroExtendExpr will not try folds if it has already memoized that the fact that this expression doesn't fold. I think we'd be better off adding a parameter to skip that check for this use-site.

Fair enough, that's why I asked. Will restructure.

Though I'm generally starting to have doubts about the direction of the whole patch stack (starting D103991). I find this kind of after the fact fixup of SCEVs rather problematic. Just the additional nowrap flags inferred during zext/sext construction can already cause hard to understand "spooky action at a distance", and this takes things one step further. I didn't really appreciate that this is where this is going.

Yeah, the problem is that "spooky action at a distance" is pretty fundamental to the interaction of trip count logic and SCEV construction. I could move this into the SCEV construction, but then we have to add a really nasty "is this scev directly used by exit test?" piece.

I have to admit I'm not really a fan of this myself, but I *really* don't see any better options. I've tried - like *really* tried, this is what resulted in the whole misadventure in indvars - but so far, I have absolutely nothing better. If you want to brainstorm, I'm happy to see if we can come up with anything better, but after a lot of thought, I've concluded this is the "least bad" place.

reames abandoned this revision.Nov 24 2021, 2:31 PM

Will reopen when I get time to return to this. Closing in the meantime to get off review queues.