[PATCH] D104867: [InstSimplify] fold extractelement of splat even with variable index

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 25 05:00:54 PDT 2021


spatel added a comment.

In D104867#2840170 <https://reviews.llvm.org/D104867#2840170>, @frasercrmck wrote:

> 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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104867/new/

https://reviews.llvm.org/D104867



More information about the llvm-commits mailing list