This is an archive of the discontinued LLVM Phabricator instance.

[IndVarSimplify][LoopUtils] rewriteLoopExitValues. NFC.
ClosedPublic

Authored by SjoerdMeijer on Jan 13 2020, 5:19 AM.

Details

Summary

This moves rewriteLoopExitValues from IndVarSimplify to LoopUtils thus making it a generic loop utility function, which should be a non-functional change. This allows to rewrite loop exit values by just calling this function without running the whole IndVarSimplify pass.

For context, we would like to (re)use rewriteLoopExitValues to rematerialize the iteration count in loop exit blocks, which allows us to optimise away better induction variable expressions in hardware-loops.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Jan 13 2020, 5:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2020, 5:19 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

These seems like a sensible thing to go along with D72714.

llvm/include/llvm/Transforms/Utils/LoopUtils.h
370

ReplaceExitValue needn't be a reference.

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
2690

Does this need the getValue()?

llvm/lib/Transforms/Utils/LoopUtils.cpp
1138

This was added but not removed anywhere?

dmgreen added inline comments.Jan 17 2020, 1:27 AM
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
718

This statistic has gone missing? (Maybe have rewriteLoopExitValues return the number of replaced values, not a bool?)

Thanks for looking! Comments addressed, the main ones being:

  • restored the statistics, and
  • the code that I forgot to delete.
dmgreen accepted this revision.Jan 17 2020, 6:08 AM

This looks useful as a separate function, the interface looks pretty clean and I think it lives nicely in LoopUtils.

LGTM.

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
2692

NumReplaced += Rewrites; maybe?

2693

Changed = true at this point.

This revision is now accepted and ready to land.Jan 17 2020, 6:08 AM
This revision was automatically updated to reflect the committed changes.