This is an archive of the discontinued LLVM Phabricator instance.

[SROA] propagate !range metadata when moving loads
ClosedPublic

Authored by arielb1 on Aug 28 2017, 9:02 AM.

Details

Summary

This tries to propagate !range metadata to a pre-existing load when a load is optimized out. This is done instead of adding an assume because converting loads to and from assumes creates a lot of IR.

This requires D37215 in order to work, but I've put it in a separate patch because it affects a different section of the code (and also for easier bisection if this introduces a regression).

Diff Detail

Repository
rL LLVM

Event Timeline

arielb1 created this revision.Aug 28 2017, 9:02 AM
hfinkel added inline comments.
lib/Transforms/Utils/Local.cpp
1893 ↗(On Diff #112906)

return here.

lib/Transforms/Utils/PromoteMemoryToRegister.cpp
315 ↗(On Diff #112906)

Huh?

318 ↗(On Diff #112906)

Brace on previous line.

328 ↗(On Diff #112906)

Two space indent.

329 ↗(On Diff #112906)

We should refactor this (calling this function here seems odd - the load is not an assume). I think that you're trying to reuse the logic here for the dominance checking, which is fine, but you don't need the isEphemeralValueOf check). Please feel free to break isValidAssumeForContext into two parts, and reuse here the first part.

330 ↗(On Diff #112906)

Odd indentation.

arielb1 updated this revision to Diff 113699.Sep 3 2017, 8:22 AM

address review comments

This looks good, but, have you checked for compile-time regressions? I'm concerned here because:

We've now made addAssumptionsFromMetadata linear in the number of instructions between the instruction and its replacement. That should be documented with the function declaration (at least). As the replacement always dominates the original instruction, when they're in the same BB, we'll always be doing that linear walk. As you're making the walk go through normal loads, I can imagine this becoming quadratic in some inputs (unless there's something about the way that SROA uses this that prevents that, and if so, we need to document that too).

If this can become quadratic, I think we'll want to maintain some kind of BB-region analysis, there we partition each BB into regions based on guaranteed execution, and then use that instead of walking.

include/llvm/Analysis/ValueTracking.h
375 ↗(On Diff #113699)

reached and executed -> later executed

lib/Transforms/Utils/PromoteMemoryToRegister.cpp
314 ↗(On Diff #113699)

Brace on previous line.

316 ↗(On Diff #113699)

Do you need the llvm:: here? If not, please remove it.

arielb1 updated this revision to Diff 113760.Sep 4 2017, 8:40 AM

Don't use ValueTracking's isGuaranteedToBeExecuted to avoid potential O(n^2). This is much uglier but should be O(n log n) in all cases.

hfinkel added inline comments.Sep 4 2017, 10:01 AM
lib/Transforms/Utils/PromoteMemoryToRegister.cpp
168 ↗(On Diff #113761)
... guaranteed to execute once the first one executes.
209 ↗(On Diff #113761)

How is that renumbering handled correctly?

Also, there's some assumption here that we don't insert new instructions that would break apart an existing internal? (I'm guessing not, as that seems like it would be a semantics-changing transformation, and we don't do that here, but we should document the assumptions here).

232 ↗(On Diff #113761)

Line too long (and you should just use auto here).

372 ↗(On Diff #113761)

Odd indentation.

420 ↗(On Diff #113761)

Odd indentation.

475–476 ↗(On Diff #113761)

Odd indentation.

578 ↗(On Diff #113761)

Odd indentation.

998 ↗(On Diff #113761)

Odd indentation.

arielb1 updated this revision to Diff 113778.Sep 4 2017, 10:41 AM

address review comments

You can benchmarks on the ValueTracking change? How did those turn out?

lib/Transforms/Utils/PromoteMemoryToRegister.cpp
172 ↗(On Diff #113778)

Variable names start with a capital letter.

264 ↗(On Diff #113778)

Start comments with a capital letter.

270 ↗(On Diff #113778)

Local variable names start with a capital letter.

280 ↗(On Diff #113778)

If we that -> If we find that

arielb1 updated this revision to Diff 113924.Sep 5 2017, 3:34 PM

address review comments

hfinkel accepted this revision.Sep 5 2017, 3:37 PM

You can benchmarks on the ValueTracking change? How did those turn out?

Great. This LGTM.

This revision is now accepted and ready to land.Sep 5 2017, 3:37 PM

This *still* hasn't committed. What is this waiting for?

Ok. I was just going over my todo list for in-progress items.

Has this still not landed in this month? Did this become blocked on anything?

Has this still not landed in this month? Did this become blocked on anything?

Once the differential is accepted, you are supposed to commit it. There is no auto-commit.
If you don't have commit rights yet, you should request them.
Or you can ask others to commit it for you.

nagisa edited edge metadata.Nov 26 2017, 1:01 AM

Would be nice if somebody committed this. None of us have the commit bit.

davide added a subscriber: davide.Nov 26 2017, 5:10 PM

Would be nice if somebody committed this. None of us have the commit bit.

Please rebase the patch on ToT and I'll commit for you.

arielb1 updated this revision to Diff 124370.Nov 27 2017, 6:40 AM

Rebased and ready to land

This revision was automatically updated to reflect the committed changes.

Ariel, we had to revert this because it broke some bots. Feel free to fix the assertion and update the patch

nox added a subscriber: nox.May 5 2018, 3:08 AM

Ariel, we had to revert this because it broke some bots. Feel free to fix the assertion and update the patch

What was the failing assertion?