[PATCH] D137934: [InstCombine] Fold extractelt with select of constants
Thomas Symalla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 18 07:05:55 PST 2022
tsymalla added a comment.
In D137934#3936962 <https://reviews.llvm.org/D137934#3936962>, @spatel wrote:
> 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.
Yeah, I have that working, but it's not going to optimize such cases like in the `shufflevector` tests for now. I'll go with bailing out for now.
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