This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Introduce VPWidenSelectRecipe (NFC).
ClosedPublic

Authored by fhahn on Apr 10 2020, 6:14 AM.

Details

Summary

Widening a selects depends on whether the condition is loop invariant or
not. Rather than checking during codegen-time, the information can be
recorded at the VPlan construction time.

This was suggested as part of D76992, to reduce the reliance on
accessing the original underlying IR values.

Diff Detail

Event Timeline

fhahn created this revision.Apr 10 2020, 6:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2020, 6:14 AM
fhahn retitled this revision from [VPlan] Introduce VPWidenSelectRecipie (NFC). to [VPlan] Introduce VPWidenSelectRecipe (NFC)..Apr 10 2020, 6:21 AM
gilr added inline comments.Apr 12 2020, 2:15 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6950

Can't be a phi at this point (actually this also holds for tryToWiden as all phi's are taken care of by tryToCreateRecipe, but that belongs in a separate patch).

6950

If statement can fold into the return expression.

llvm/lib/Transforms/Vectorize/VPlan.cpp
724

Should also print InvariantCond as e.g. in VPWidenGEPRecipe::print()

fhahn updated this revision to Diff 256846.Apr 12 2020, 3:18 AM

Address comments, thanks!

Simplify willWiden check, print whether condition is invariant or not.

fhahn marked 2 inline comments as done.Apr 12 2020, 3:21 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6950

Done! I think it would make sense to move all those checks into a separate function now, that there are multiple users. I'll do that as a follow up.

llvm/lib/Transforms/Vectorize/VPlan.cpp
724

Done, but I am not sure how to best print it specifically for the condition. I've added a note to the debug output.

gilr added inline comments.Apr 12 2020, 6:09 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6940

SI is not used beyond this point until recipe construction. Better to either use it consistently instead of I or only check isa<> here and cast<> at recipe construction.

6944

This can fold into willWiden.

llvm/lib/Transforms/Vectorize/VPlan.cpp
724

Agree, standardizing how to mark invariant operands would be easier for recipes using VPValues (e.g. just adding "[Inv]" before/after invariant operands).

725

Since it's an infrequent optimization it might be cleaner to only print if relevant, i.e. " << (InvariantCond ? " (condition is loop invariant)" : "").

fhahn updated this revision to Diff 256851.Apr 12 2020, 6:56 AM
fhahn marked 4 inline comments as done.

Address comments, thanks!

fhahn added inline comments.Apr 12 2020, 7:03 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6940

changed to use it throughout.

fhahn updated this revision to Diff 256856.Apr 12 2020, 7:30 AM

Fix type in comment.

gilr accepted this revision.Apr 12 2020, 8:35 AM

LGTM, thanks!

This revision is now accepted and ready to land.Apr 12 2020, 8:35 AM
Ayal added inline comments.Apr 12 2020, 4:29 PM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
4420

A separate, independent nit, while we're here: get or create only values that are needed:

auto *ScalarCond = (InvariantCond ? getOrCreateScalarValue(I.getOperand(0), {0, 0}) : nullptr);
4423

Value *Cond = (InvariantCond ? ScalarCond : getOrCreateVectorValue(I.getOperand(0), Part));

4426

Value *Sel = Builder.CreateSelect(Cond, Op0, Op1);

fhahn marked an inline comment as done.Apr 13 2020, 12:35 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
4420

+1, but it requires a few small test changes. I'll fix in a separate patch.

This revision was automatically updated to reflect the committed changes.