[PATCH] D137934: [InstCombine] Fold extractelt with select of constants

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 07:01:58 PST 2022


spatel added a comment.

In D137934#3928765 <https://reviews.llvm.org/D137934#3928765>, @tsymalla wrote:

> @spatel Thanks for adding these tests. These work in general, except the case where the second operand of the ExtractElement instruction is not a constant. The reason is that currently `constantFoldOperationIntoSelectOperand` expects both operands to be either the original select or a constant, but not an additional select, so a new extractelement instruction can be created to extract the actual value. If one of the operands is another select, it could be obvious that the sequence shows OOB behavior:
>
>   %e = select i1 %c, i32 3, i32 4
>   %s = select i1 %c, <3 x i32> <i32 2, i32 3, i32 4>, <3 x i32> <i32 5, i32 6, i32 7>
>   %r = extractelement <3 x i32> %s, i32 %e
>   ret i32 %r
>
> Even if I know how to make the regular case work, I'll wrap my head around that particular issue.

Just bail out if the extract index value is not an immediate constant? The case where the index value is a select-of-constants that can be reduced might be another patch, but that doesn't seem like a common pattern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137934



More information about the llvm-commits mailing list