This is an archive of the discontinued LLVM Phabricator instance.

[LoopIdiom] Ignore memory accesses to constant memory
AbandonedPublic

Authored by aeubanks on Apr 23 2021, 11:26 AM.

Details

Reviewers
lebedev.ri
nikic
Summary

A loop wasn't recognized as a memcpy because the load was thought to
potentially alias with the store. We should ignore memory operations to
constant memory since moving instructions around cannot change their
results.

Diff Detail

Event Timeline

aeubanks created this revision.Apr 23 2021, 11:26 AM
aeubanks requested review of this revision.Apr 23 2021, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2021, 11:26 AM
xbolva00 added inline comments.
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
881

just return true; (no else)

aeubanks added inline comments.Apr 23 2021, 11:40 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
881

then the newly introduced if condition is useless if we always return true

xbolva00 added inline comments.Apr 23 2021, 11:41 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
881

yeah, oh! sorry:)

While this works, I don't think this really addresses the root problem of D101017. Your example already folds fine with -globals-aa -loop-idiom. If GlobalsAA is not available at the time LoopIdiom runs, then that's a bug...

nikic added inline comments.Apr 23 2021, 11:54 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
876

Without looking at the users of this function, just going by the contract on the function, I think you can only do this if Access is Mod (as you can't write to constant memory), but not if Access is Ref or ModRef.

aeubanks abandoned this revision.Apr 23 2021, 12:03 PM

While this works, I don't think this really addresses the root problem of D101017. Your example already folds fine with -globals-aa -loop-idiom. If GlobalsAA is not available at the time LoopIdiom runs, then that's a bug...

oh you're right, for some reason I thought this transform wasn't happening even with globals-aa