This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] fold extractelement of splat even with variable index
ClosedPublic

Authored by spatel on Jun 24 2021, 10:38 AM.

Details

Summary

We unnecessarily restricted a fold of a splat to a constant vector.

We overlooked this fold in D102404 and earlier patches, but the fixed vector variant is shown in:
https://llvm.org/PR50817

Alive2 agrees on that:
https://alive2.llvm.org/ce/z/HpijPC

I don't think Alive2 understands scalable vectors, but the same logic applies IIUC.

Diff Detail

Event Timeline

spatel created this revision.Jun 24 2021, 10:38 AM
spatel requested review of this revision.Jun 24 2021, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2021, 10:38 AM

I agree that fixed- and scalable-vectors should be treated identically, at least according to my reading.

As for the legality, so even though %idx may exceed the length of the vector and return a poison value, it's acceptable for us to "relax" that into undef and then immediately into the splat value? Is that what's going on?

I agree that fixed- and scalable-vectors should be treated identically, at least according to my reading.

As for the legality, so even though %idx may exceed the length of the vector and return a poison value, it's acceptable for us to "relax" that into undef and then immediately into the splat value? Is that what's going on?

Yes, exactly - in the post-undef world, I think we would say: since the index is out-of-bounds, the result of the operation is poison (arbitrary), so we are choosing the splat value for convenience in making this fold.

If we wanted to, we could try to detect if the index is always out-of-bounds (via known bits) and return poison instead of the splat value (similar to the existing code that handles a constant index value). But that would have potentially large compile-time cost and no practical value IMO.

RKSimon accepted this revision.Jul 5 2021, 3:05 AM

LGTM - thanks @spatel

This revision is now accepted and ready to land.Jul 5 2021, 3:05 AM