This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Updates to arm-block-placement pass
ClosedPublic

Authored by malharJ on Mar 31 2021, 4:22 AM.

Details

Summary

The patch makes two updates to the arm-block-placement pass:

  • Handle arbitrarily nested loops
  • Extends the search (for t2WhileLoopStartLR) to the predecessor of the preHeader.

Diff Detail

Event Timeline

malharJ created this revision.Mar 31 2021, 4:22 AM
malharJ requested review of this revision.Mar 31 2021, 4:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2021, 4:22 AM
malharJ retitled this revision from [ARM] Updates the arm-block-placement pass to handle arbitrarily nested loops and also extends the search for t2WhileLoopStartLR to the predecessor of the preHeader. to [ARM] Updates to arm-block-placement pass.Mar 31 2021, 4:28 AM
malharJ edited the summary of this revision. (Show Details)
samparker added inline comments.Mar 31 2021, 5:00 AM
llvm/lib/Target/ARM/ARMBlockPlacement.cpp
72

Consider renaming this helper, it currently reads like it would be returning a WLS instruction.

89

return bool instead of using 'Changed'?

Thanks for the patch. Looks like a nice improvement.

llvm/lib/Target/ARM/ARMBlockPlacement.cpp
78

It may be best to make sure that Preheader has a single successor too, to make sure it doesn't look at a completely different block.

(Preheader->pred_begin()) doesn't need brackets.

95

Does this need to loop any more? It's already found a ARM::t2WhileLoopStartLR.

180

doesnt -> Doesn't

I'm not sure what this comment is adding. It's probably better to just rename Preheader to Predecessor, if the name is wrong.

189

It's better to return a bool for Changed than take it by reference.

malharJ updated this revision to Diff 334427.Mar 31 2021, 6:35 AM
malharJ marked 6 inline comments as done.

Changed some functions to return boolean instead of using
parameter by reference + some minor updates.

llvm/lib/Target/ARM/ARMBlockPlacement.cpp
180

Had left the comment by accident. I agree and I've renamed the variable now.

dmgreen added inline comments.Mar 31 2021, 9:57 AM
llvm/lib/Target/ARM/ARMBlockPlacement.cpp
203

It still probably doesn't need to search for it. If we've found it once, we can just return the WLS instruction.

Also LLVM capitalizes variable names.

205

changed -> Changed

207

Changed |= processPostOrderLoops(..)

malharJ updated this revision to Diff 334496.Mar 31 2021, 11:23 AM
malharJ marked 3 inline comments as done.

Added some formatting + minor updates

malharJ added inline comments.Mar 31 2021, 11:26 AM
llvm/lib/Target/ARM/ARMBlockPlacement.cpp
203

yeah, I thought I'd keep the interface a little clean by not returning a pair.
I've made the update now though.

dmgreen added inline comments.Apr 1 2021, 3:12 AM
llvm/lib/Target/ARM/ARMBlockPlacement.cpp
203

Maybe just return the MachineInstr and use Predecessor = WlsInstr->getParent()? I agree not using the pair is a little cleaner.

206

Nit: We don't need brackets around a single statement.

malharJ updated this revision to Diff 334650.Apr 1 2021, 4:49 AM
malharJ marked 2 inline comments as done.

addressed comments,
renamed some functions,
added comments to test (and updated)
updated some incorrect code:

  • adjustBBOffsetsAfter() is called with BBPrevious as input since BB is moved, which would cause change in offsets after it.
  • code checking for LE to loopExit now starts search from the MBB after loopExit. Updated the test accordingly.

addressed comments,
renamed some functions,
added comments to test (and updated)
updated some incorrect code:

  • adjustBBOffsetsAfter() is called with BBPrevious as input since BB is moved, which would cause change in offsets after it.
  • code checking for LE to loopExit now starts search from the MBB after loopExit. Updated the test accordingly.

This seems to have grown from a patch that already fixing 2 things, to a patch that does many more. Can we try and keep it simple, fixing only the problems it was fixing and separate any other issues to another patch?

llvm/lib/Target/ARM/ARMBlockPlacement.cpp
80

This doesn't need brackets around (Predecessor->pred_size() == 1)

I would also change this code to be something more like:

MachineBasicBlock *Predecessor = ML->getLoopPreheader();
if (!Predecessor)
  return nullptr;
MachineInstr *WlsInstr = findWLSInBlock(Predecessor);
if (WlsInstr)
  return WlsInstr;
if (Predecessor->pred_size() != 1)
  return nullptr;
return findWLSInBlock(*Predecessor->pred_begin());

LLVM prefers those early exits.

malharJ updated this revision to Diff 335201.Apr 4 2021, 10:49 PM
malharJ marked an inline comment as done.

addressed comments,
reverted extra changes as suggested by review comment, these will be better as a separate patch.

malharJ marked an inline comment as not done.Apr 4 2021, 11:41 PM
malharJ added inline comments.
llvm/lib/Target/ARM/ARMBlockPlacement.cpp
78

Can we leave it as getLoopPredecessor() for now, ie. avoiding the strict requirement of a single successor ?
This would be helpful in keeping it flexible when making the WLSTP transform.

203

Ah, thanks.

malharJ updated this revision to Diff 335213.Apr 5 2021, 12:28 AM
malharJ marked 2 inline comments as not done.

relaxed requirement for predecessor to have single successor when searching for WLS

dmgreen accepted this revision.Apr 7 2021, 3:22 AM

Thanks. LGTM

llvm/lib/Target/ARM/ARMBlockPlacement.cpp
180

These sentences can end in full stops.

This revision is now accepted and ready to land.Apr 7 2021, 3:22 AM
This revision was automatically updated to reflect the committed changes.