This is an archive of the discontinued LLVM Phabricator instance.

[NFC][LoopIdiom] Let processLoopStoreOfLoopLoad take StoreSize as SCEV instead of unsigned
ClosedPublic

Authored by eopXD on Aug 18 2021, 4:07 AM.

Details

Summary

Letting it take SCEV allows further modification on the function to optimize
if the StoreSize / Stride is runtime determined.

The plan is to let memcpy / memmove deal with runtime-determined sizes, just
like what D107353 did to memset.

Diff Detail

Event Timeline

eopXD created this revision.Aug 18 2021, 4:07 AM
eopXD requested review of this revision.Aug 18 2021, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2021, 4:07 AM
eopXD added inline comments.Aug 18 2021, 4:15 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
861

Renamed here for better readability. Also, future patch will deal with both constant / non-constant stride, so StoreStride, LoadStride will be in type SCEV.

bmahjour added inline comments.Aug 18 2021, 11:17 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
890–891

why not:

return processLoopStoreOfLoopLoad(Dest, Source, SE->getSCEV(SizeInBytes),

?

1247

StorePtr->getType() is the type of the pointer, did you mean SI->getValueOperand()->getType()?

1281

this is being sign extended but SCEV being passed to processLoopStoreOfLoopLoad is created using ScalarEvolution::getConstant with the default value of false for the isSigned parameter.

1281
/// TODO: until non-constant sizes are handled
assert(ConstStoreSize && "store size is expected to be a constant");

or add logic to deal with non-constant situations.

eopXD updated this revision to Diff 367419.Aug 19 2021, 1:13 AM
eopXD marked 4 inline comments as done.

Address comments.

eopXD updated this revision to Diff 367420.Aug 19 2021, 1:14 AM

Fix clang-format warnings.

eopXD added inline comments.Aug 19 2021, 1:16 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
890–891

Yes you are right. This way better shows this is an NFC.

1247

The StoreSizeSCEV would be used to calculate base address of the pointer if the loop is in negative stride. So its type should be the same with SI->getPointerOperand(), which is equivalent to StorePtr->getType().

bmahjour accepted this revision.Aug 20 2021, 6:36 AM
This revision is now accepted and ready to land.Aug 20 2021, 6:36 AM
eopXD added a comment.Aug 20 2021, 7:28 AM

Thank you @bmahjour for reviewing! I am now going to commit and the next patch would want to let memcpy and memmove deal with runtime size.