This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes] Factor in vscale_range when widening insert_subvector
ClosedPublic

Authored by luke on Jun 22 2023, 3:46 AM.

Details

Summary

Currently when widening operands for insert_subvector nodes, we check
first that the indices are valid by seeing if the subvector is
statically known to be smaller than or equal to the in-place vector.

However if we're inserting a fixed subvector into a scalable vector we rely on
the minimum vector length of the latter. This patch extends the widening logic
to also take into account the minimum vscale from the vscale_range attribute,
so we can handle more scenarios where we know the scalable vector is large
enough to contain the subvector.

Fixes https://github.com/llvm/llvm-project/issues/63437

Diff Detail

Event Timeline

luke created this revision.Jun 22 2023, 3:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 3:46 AM
luke requested review of this revision.Jun 22 2023, 3:46 AM
luke edited the summary of this revision. (Show Details)Jun 22 2023, 3:47 AM
luke retitled this revision from [RISCV] Widen insert_subvector ops for fixed insert into scalable to [LegalizeTypes] Widen insert_subvector ops for fixed insert into scalable.

Is it possible for the widened type to exceed the minimum vscale?

craig.topper added inline comments.Jun 22 2023, 8:08 AM
llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
498

This test already passes. v3i64 widens to v4i64 which should be detected as less than or equal to nxv4i64.

luke added a comment.Jun 22 2023, 9:27 AM

Is it possible for the widened type to exceed the minimum vscale?

Yes, but I think that would still fall under the "If this condition cannot be determined statically but is
false at runtime, then the result vector is undefined." part of insert_subvector's definition. Since we currently already lower an insert_subvector of e.g. v8i32 into nxv4i32

llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
498

Argh, copy and paste error, should be nxv2i64

luke updated this revision to Diff 533658.Jun 22 2023, 9:34 AM

Fix test vector size

luke marked an inline comment as done.Jun 22 2023, 9:35 AM

Is it possible for the widened type to exceed the minimum vscale?

Yes, but I think that would still fall under the "If this condition cannot be determined statically but is
false at runtime, then the result vector is undefined." part of insert_subvector's definition. Since we currently already lower an insert_subvector of e.g. v8i32 into nxv4i32

What if vscale min is 3(not possible for RISC-V but this is generic code), and the types are nxv1i64 and v3i64. The operation is defined for those types, but when v3i64 gets widened to v4i64 it becomes undefined.

luke added a comment.Jun 22 2023, 9:50 AM

Is it possible for the widened type to exceed the minimum vscale?

Yes, but I think that would still fall under the "If this condition cannot be determined statically but is
false at runtime, then the result vector is undefined." part of insert_subvector's definition. Since we currently already lower an insert_subvector of e.g. v8i32 into nxv4i32

What if vscale min is 3(not possible for RISC-V but this is generic code), and the types are nxv1i64 and v3i64. The operation is defined for those types, but when v3i64 gets widened to v4i64 it becomes undefined.

Right, I see now. Could we then lower it as a series of insert_vector_elt?

Is it possible for the widened type to exceed the minimum vscale?

Yes, but I think that would still fall under the "If this condition cannot be determined statically but is
false at runtime, then the result vector is undefined." part of insert_subvector's definition. Since we currently already lower an insert_subvector of e.g. v8i32 into nxv4i32

What if vscale min is 3(not possible for RISC-V but this is generic code), and the types are nxv1i64 and v3i64. The operation is defined for those types, but when v3i64 gets widened to v4i64 it becomes undefined.

Right, I see now. Could we then lower it as a series of insert_vector_elt?

Yeah I think the ultimate fallback can be a series of insert_vector_elts. For the original failing case, it looks like we have the vscale_range attribute so we could use the minimum vscale to guarantee safety?

luke updated this revision to Diff 533805.Jun 22 2023, 3:32 PM

Rework to check for min vscale

luke updated this revision to Diff 548563.Aug 9 2023, 4:36 AM

Rebase and fix using the unwidened SubVec VT.

Gentle ping, https://github.com/llvm/llvm-project/issues/63437 still seems
to crash on ToT, and this might be good to fix for the next llvm-17 rc

luke retitled this revision from [LegalizeTypes] Widen insert_subvector ops for fixed insert into scalable to [LegalizeTypes] Factor in vscale_range when widening insert_subvector.Aug 9 2023, 4:37 AM
luke edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Aug 12 2023, 10:56 AM