This is an archive of the discontinued LLVM Phabricator instance.

[LSR] Fix "new use of poison" problem in lsr-term-fold
ClosedPublic

Authored by reames on Mar 20 2023, 3:10 PM.

Details

Summary

This models the approach used in LFTR. The short summary is that we need to prove the IV is not dead first, and then we have to either prove the poison flag is valid after the new user or delete it.

There are two key differences between this and LFTR.

First, I allow a non-concrete start to the IV. The goal of LFTR is to canonicalize and IVs with constant starts are canonical, so the very restrictive definition there is mostly okay. Here on the other hand, we're explicitly moving *away* from the canonical form, and thus need to handle non-constant starts.

Second, LFTR bails out instead of removing inbounds on a GEP. This is a pragmatic tradeoff since inbounds is hard to infer and assists aliasing. This pass runs very late, and I think the tradeoff runs the other way.

A different approach we could take for the post-inc check would be to perform a pre-inc check instead of a post-inc check. We would still have to check the pre-inc IV, but that would avoid the need to drop inbounds. Doing the pre-inc check would basically trade killing a whole IV for an extra register move in the loop. I'm open to suggestions on the right approach here.

Note that this analysis is quite expensive compile time wise. I have made no effort to optimize (yet).

Diff Detail

Event Timeline

reames created this revision.Mar 20 2023, 3:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 3:10 PM
reames requested review of this revision.Mar 20 2023, 3:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 3:10 PM
reames edited the summary of this revision. (Show Details)Mar 20 2023, 3:16 PM
nikic accepted this revision.Mar 21 2023, 3:47 AM

LGTM

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6814

recurrence

This revision is now accepted and ready to land.Mar 21 2023, 3:47 AM
This revision was landed with ongoing or failed builds.Mar 21 2023, 8:23 AM
This revision was automatically updated to reflect the committed changes.