This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Prepare EarlyCSE to work with non-instruction values
AbandonedPublic

Authored by mkazantsev on Apr 27 2017, 2:13 AM.

Details

Summary

Conditional branching, intrinsics experimental_guard and assume may state that their arguments are true/false.
This patch performs a refactoring (which is supposed to be a NFC) that changes interface and internals of SimpleValue
to accept Values instead of Instructions. Currently, all non-instruction values get rejected on in canHandle method to
preserve the existing behavior, but this will change in a follow-up patch.

Diff Detail

Event Timeline

reames requested changes to this revision.Apr 27 2017, 7:01 PM
reames added inline comments.
lib/Transforms/Scalar/EarlyCSE.cpp
68

These three cover functions seem to obscure more than they help clarify. Or at least they did for me. I'd advice removing them and just directly working with the Val field.

82

A tactical suggestion here: do the refactoring to change all the types w/o actually adding values to the canHandle predicate then separately check in the change which actually allows the Values to flow through. (i.e. basically return false here in the initial patch)

The reasoning here is that if this does expose a problem (miscompile, crash, etc..), knowing whether you made a mistake in the refactoring part or if the value handling itself was the actual guilty party will be useful.

Not a required change, but something I would encourage.

112

This would be more idiomatic as:
Instruction *Inst = dyn_cast<Instruction>(Val.Val);
if (!Inst)

return hash_combine(Val.Val);
This revision now requires changes to proceed.Apr 27 2017, 7:01 PM
mkazantsev updated this revision to Diff 97076.Apr 28 2017, 3:51 AM
mkazantsev edited edge metadata.
mkazantsev marked 3 inline comments as done.
mkazantsev retitled this revision from [EarlyCSE] Teach EarlyCSE to work with non-instruction values to [EarlyCSE] Prepare EarlyCSE to work with non-instruction values.
mkazantsev edited the summary of this revision. (Show Details)

Splitting the change into two. This becomes a non-functional change of SimpleValue interface and internals.

minor comments, once addressed looks likely ready to go. I do want to see the fixed patch before submission.

lib/Transforms/Scalar/EarlyCSE.cpp
90

Don't these need to change as well?

102

cast is a checked cast. The previous assert is unnecessary.

152

Again, checked casts.

reames requested changes to this revision.Apr 29 2017, 11:57 AM
This revision now requires changes to proceed.Apr 29 2017, 11:57 AM
mkazantsev updated this revision to Diff 97392.May 1 2017, 11:02 PM
mkazantsev edited edge metadata.
mkazantsev marked 3 inline comments as done.

Addressed comments.

reames accepted this revision.May 2 2017, 9:39 AM

LGTM.

This revision is now accepted and ready to land.May 2 2017, 9:39 AM

Hold this until https://reviews.llvm.org/D32641 is done properly. This patch does not make sense separately.

mkazantsev abandoned this revision.Jun 13 2017, 1:46 AM

Abandoning it so far, maybe will return to it in future.