This is an archive of the discontinued LLVM Phabricator instance.

[LV] Remove constant-step restriction for vector phi creation
ClosedPublic

Authored by mssimpso on Feb 14 2017, 11:52 AM.

Details

Summary

We previously only created a vector phi node for an induction variable if its step had a constant integer type. However, the step actually only needs to be loop-invariant. This patch allows a non-constant step if it is loop-invariant and has an integer type.

Event Timeline

mssimpso created this revision.Feb 14 2017, 11:52 AM
mkuper edited edge metadata.Feb 15 2017, 4:06 PM

Thanks, Matt!
A few minor comments inline.

lib/Transforms/Vectorize/LoopVectorize.cpp
2369

Can this really be anything but a trunc? If not, why not CreateTrunc?

2377

Maybe it should? :-)
(I wouldn't block this patch on that, but please mark this as a FIXME.)

2456

This doesn't add any new overhead - we'd expand this SCEV into the pre-header anyway, for the scalar induction, right?

2481

Same as above.

test/Transforms/LoopVectorize/induction-step.ll
201

Do we have a negative test-case showing we don't try anything stupid for loop-variant values?

mssimpso added inline comments.Feb 16 2017, 6:43 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
2369

It's always a trunc - I thought about that after submitting - I'll update it.

2377

I agree. I'll add FIXME here for now.

2456

Right, no new overhead here. We're just expanding early if the step is loop-invariant. The existing expansion is performed a bit further down at line 2497 (for the scalar IVs and the splat vector IVs).

The insertion point for the existing expansion has always been the current IRBuilder insertion point, which is actually within the body of the loop. But for a loop-invariant step, SCEVExpander is smart enough to place it in the pre-header.

test/Transforms/LoopVectorize/induction-step.ll
201

I'll add one.

mssimpso added inline comments.Feb 16 2017, 7:22 AM
test/Transforms/LoopVectorize/induction-step.ll
201

Actually, we don't handle inductions with loop-variant steps at all (InductionDescriptor::isInductionPHI). So I'll probably change the patch to assert instead of checking for loop-invariance.

mssimpso updated this revision to Diff 88740.Feb 16 2017, 8:33 AM
mssimpso marked 4 inline comments as done.

Addressed Michael's comments.

  • Used CreateTrunc instead of CreateSExtOrTrunc.
  • Marked IRBuilder comment FIXME.
  • Changed loop-invariant check to an assertion (InductionDescriptor only allows loop-invariant steps) and simplified.
mkuper accepted this revision.Feb 16 2017, 1:12 PM

LGTM

This revision is now accepted and ready to land.Feb 16 2017, 1:12 PM
This revision was automatically updated to reflect the committed changes.