This is an archive of the discontinued LLVM Phabricator instance.

[LV] Update generateInstruction to return produced value (NFC).
ClosedPublic

Authored by fhahn on Jun 30 2023, 10:48 AM.

Details

Summary

Update generateInstruction to return the produced value instead of
setting it for each opcode. This reduces the amount of duplicated code
and is a preparation for D153696.

Diff Detail

Event Timeline

fhahn created this revision.Jun 30 2023, 10:48 AM
fhahn requested review of this revision.Jun 30 2023, 10:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 10:48 AM
Herald added a subscriber: vkmr. · View Herald Transcript
Ayal added a comment.Jul 1 2023, 2:00 PM

Thanks for following-up on this!
Adding some comments to hopefully further simplify and clarify the roles of generateInstruction() vs. execute().

llvm/lib/Transforms/Vectorize/VPlan.h
850–854

This method should arguably always generate an Instruction and return it. What to do with the generated Instruction, when this recipe !hasResult, could be left to the caller.
Cases that currently do not generate any instruction should be optimized away by (a) having the caller recognize that a single value is needed per all parts, and (b) hooking up existing values directly to their users w/o going through a VPInstruction. These can be dealt with separately, by subsequent patches.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
275

Note that in this case an existing Value is returned rather than a newly generated Instruction.

290

Once the caller recognizes this as a uniform recipe, it should call it with Part zero only, and this "if" should be replaced by an assert.

307

Another case where an existing Value is returned instead of a newly generated instruction.
(Optimizing away a redundant add-with-zero for Part zero by not creating it rather than Builder folding.)

316

Once the caller recognizes this as a uniform recipe, it should call it with Part zero only, and this "if" should be replaced by an assert.

333

Perhaps better return CondBr, i.e., have generateInstruction() always return the instruction it generates (or an existing Value) and have the caller reason about setting it in State if hasResult/users or not?

337

Once the caller recognizes this as a uniform recipe, it should call it with Part zero only, and this "if" should be replaced by an assert.

357

Better return CondBr?

370

Check instead if (!hasResult() - also considers e.g. stores) or !have any user?
This is only to save compile-time - should be ok to set the State in any case, also if V is a branch (or null) - the State should not be get'd later if this VPInstruction has no result or users.

fhahn updated this revision to Diff 536906.Jul 3 2023, 2:57 PM
fhahn marked 8 inline comments as done.

Address latest comments, thanks!

llvm/lib/Transforms/Vectorize/VPlan.h
850–854

updated thanks!

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
290

Will do thanks!

307

Right, builder fold should be added in D152660.

316

Will do, thanks!

333

Updated, thanks!

337

Will do, thanks!

357

updated, thanks!

370

Updated to check hasResult, thanks!

fhahn updated this revision to Diff 537036.Jul 4 2023, 3:59 AM

Remove unused Next variable.

fhahn updated this revision to Diff 537038.Jul 4 2023, 4:01 AM

Rename V -> GeneratedValue in line with follow-up patch D153696.

Ayal accepted this revision.Jul 4 2023, 6:14 AM

Thanks for following-up on this, ship it!

This revision is now accepted and ready to land.Jul 4 2023, 6:14 AM
This revision was landed with ongoing or failed builds.Jul 5 2023, 11:54 AM
This revision was automatically updated to reflect the committed changes.