This is an archive of the discontinued LLVM Phabricator instance.

[LV] Use IRBuilder to create and optimize middle-block compare.
ClosedPublic

Authored by fhahn on Aug 19 2023, 7:04 AM.

Details

Summary

Split off from D150398 to avoid builder-related diff changes there.
Using IRBuilder to create ICmps simplifies the result if both operands
are constants.

Diff Detail

Event Timeline

fhahn created this revision.Aug 19 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2023, 7:04 AM
fhahn requested review of this revision.Aug 19 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2023, 7:04 AM
Ayal added a comment.Aug 27 2023, 11:01 AM

Rather than have IRBuilder detect and optimize this implicitly at code-gen/ILV::completeLoopSkeleton() time, better do so explicitly at VPlan transform time, probably after VF and UF have been set, i.e., optimize the compare and conditional branch recipes into an unconditional branch recipe. Is the intent to do so as a subsequent patch? If so would be good to add a TODO to replace IRBuilder here; code-gen should ideally be straightforward.

nit: typo in title. The use of IRBuilder to create the compare also optimizes it.

fhahn retitled this revision from [LV] Use IRBuidlder to create middle-block compare. to [LV] Use IRBuilder to create and optimize middle-block compare..Aug 28 2023, 6:29 AM
fhahn updated this revision to Diff 553913.Aug 28 2023, 6:37 AM

Rather than have IRBuilder detect and optimize this implicitly at code-gen/ILV::completeLoopSkeleton() time, better do so explicitly at VPlan transform time, probably after VF and UF have been set, i.e., optimize the compare and conditional branch recipes into an unconditional branch recipe. Is the intent to do so as a subsequent patch? If so would be good to add a TODO to replace IRBuilder here; code-gen should ideally be straightforward.

The immediate goal is to bring this code in line with how VPInstruction creates compares, so the diff for D150398 is as small as possible.

Once we have the branch modeled in VPlan, we should simplify it there directly as well, but this patch is a first step to get there, I added a TODO.

nit: typo in title. The use of IRBuilder to create the compare also optimizes it.

Typo should be fixed, thanks!

Ayal accepted this revision.Aug 28 2023, 7:36 AM

Rather than have IRBuilder detect and optimize this implicitly at code-gen/ILV::completeLoopSkeleton() time, better do so explicitly at VPlan transform time, probably after VF and UF have been set, i.e., optimize the compare and conditional branch recipes into an unconditional branch recipe. Is the intent to do so as a subsequent patch? If so would be good to add a TODO to replace IRBuilder here; code-gen should ideally be straightforward.

The immediate goal is to bring this code in line with how VPInstruction creates compares, so the diff for D150398 is as small as possible.

Well, better avoid optimizing compares implicitly by VPInstruction's code-gen as well... but the goal is clear.

Once we have the branch modeled in VPlan, we should simplify it there directly as well, but this patch is a first step to get there, I added a TODO.

Thanks! Simplification is for both compare and branch.

This revision is now accepted and ready to land.Aug 28 2023, 7:36 AM