This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Delay forgetValue() call
AbandonedPublic

Authored by nikic on Jun 29 2020, 11:56 AM.

Details

Summary

While working on D82730 I ran into a case where nearly all compile-time is spent inside the forgetValue() call in rewriteLoopExitValues(). Currently it forgets values eagerly, regardless of whether the phi node will actually get replaced or not. This patch moves the forgetValue() call to just before the phi gets replaced, so we don't waste time forgetting values that don't get changed.

However, this causes a test change in elim-extend.ll. The reason is that an earlier Phi node replacement in IV widening did not perform the forgetValue() call, and as such left behind stale SCEVs (still correct, but possibly sub-accurate). Insert the missing call.

Diff Detail

Event Timeline

nikic created this revision.Jun 29 2020, 11:56 AM

Compile-time numbers: There's various minor improvements, and larger ones for ClamAV (2% in LTO -g configuration). So it seems that this does affect more than just the particularly pathological case I hit.

fhahn added a subscriber: fhahn.Jul 14 2020, 6:37 AM

I think there might be more cases where we miss proper invalidation now. When building MultiSource & SPEC2006 with the patch, there are ~20 binary changes (out of 237)

nikic planned changes to this revision.Jul 14 2020, 2:58 PM

@fhahn Thanks for taking a look!

For the first diff I checked, the issue appears to be lack of "ext of min/max" to "min/max of ext" canonicalization in SCEV. Which is a peculiar oversight, because SCEV already tries to push exts through most everything else. I'll try adding that.

fhahn added a comment.Jul 14 2020, 3:13 PM

@fhahn Thanks for taking a look!

For the first diff I checked, the issue appears to be lack of "ext of min/max" to "min/max of ext" canonicalization in SCEV. Which is a peculiar oversight, because SCEV already tries to push exts through most everything else. I'll try adding that.

Sounds good. I could also take a look tomorrow, if you could share a test case.

nikic abandoned this revision.Oct 30 2021, 1:22 AM

Abandoning as a variant of this landed in D111495.