This is an archive of the discontinued LLVM Phabricator instance.

[GVN LoadPRE] Extend the scope of optimization by using context to prove safety of speculation
ClosedPublic

Authored by skatkov on Oct 2 2020, 3:09 AM.

Details

Summary

Use context to prove that load can be safely executed at a point where load is being hoisted.

Postpone the decision about safety of speculative load execution till the moment we know
where we hoist load and check safety at that context.

Diff Detail

Event Timeline

skatkov created this revision.Oct 2 2020, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 2 2020, 3:09 AM
skatkov requested review of this revision.Oct 2 2020, 3:09 AM
lebedev.ri added inline comments.Oct 2 2020, 3:21 AM
llvm/test/Transforms/GVN/loadpre-context.ll
1

Precommit please

mkazantsev added inline comments.Oct 2 2020, 3:49 AM
llvm/lib/Transforms/Scalar/GVN.cpp
1248

Why is that needed? We split critical edges right below. As far as I understand, we will insert loads into newly created split blocks which is safe.

skatkov added inline comments.Oct 2 2020, 3:59 AM
llvm/lib/Transforms/Scalar/GVN.cpp
1248

Imaging that we have a guard for null check in load's basic block and we plan to skip it (speculate). If we hoist load over this guard we can end up with a load from null address. This is not correct. We must ensure that on end of spilt block == entry to our basic block address can be proved a non-null.

skatkov updated this revision to Diff 295786.Oct 2 2020, 4:01 AM

test is precomitted.

reames accepted this revision.Oct 2 2020, 8:59 AM
reames added a subscriber: reames.

LGTM w/minor fixes.

llvm/lib/Transforms/Scalar/GVN.cpp
1171–1172

Use "|=" please.

llvm/test/Transforms/GVN/loadpre-context.ll
4

"address" not "adress". Consistent spelling mistake in file, please fix.

98

I think your comment is missing some punctuation. This reads very oddly, reword please.

151

Please rename this to something like ro_foo. i.e. make the name explicit about being read only.

Alternatively, use the readnone attribute on the call instruction, not the decl.

Otherwise, you confuse the reader because it looks like you're hoisting a load past a mutating call. I had a comment all written before thinking to check the declaration. :)

This revision is now accepted and ready to land.Oct 2 2020, 8:59 AM

Seems fine to me overall.

llvm/lib/Transforms/Scalar/GVN.cpp
1152–1154

This variable name doesn't parse for me.
Perhaps something like MustEnsureSafetyOfSpeculativeExecutetion

skatkov added inline comments.Oct 4 2020, 7:28 PM
llvm/lib/Transforms/Scalar/GVN.cpp
1171–1172

I do not need to execute ICF->hasICF(TmpBB) if I know that I need safe speculation already.

gives me exactly this wil= will force the redundant execution of ICF->hasICF(TmpBB).
skatkov updated this revision to Diff 296095.Oct 4 2020, 9:41 PM

Handled comments. Will wait for a day to give a chance for Roman, Philip and Max to take a look one more time.

mkazantsev accepted this revision.Oct 4 2020, 9:45 PM