[PATCH] D138874: [InstCombine] canonicalize trunc + insert as bitcast + shuffle, part 3

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 04:59:26 PST 2022


spatel added a comment.

In D138874#3980790 <https://reviews.llvm.org/D138874#3980790>, @dmgreen wrote:

>> Thanks for the update - so there has been some fallout.
>>
>> I agree that trunc+insert is simpler in the basic case. The challenge is that we haven't found any other way to solve the motivating bug. Leaving it to the backend is too late, so we need to convert a chain of inserts into a shuffle in IR to get the optimal result.
>>
>> This line of patches got us at least partially there. If we convert back to insert at SDAG builder/combine time, that seems like it could mitigate the problems. If that's not feasible, then I think we should revert the preceding patches in this set.
>
> Yeah I don't know of a better way to fix it, I'm afraid. There is a quick fix for the regressions I ran into in D139611 <https://reviews.llvm.org/D139611>.

After thinking this over again, we should be able to add a more specific peephole that finds the common source op by looking through shifts and casts:
https://alive2.llvm.org/ce/z/_4iTEu
It's bigger than the typical pattern match, but it's not that bad. It could start off very narrow and be generalized in a few steps. 
That avoids creating a shuffle, so it sidesteps the backend problems noted here. The question of whether we should canonicalize in the opposite direction from this patch is still open.


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

https://reviews.llvm.org/D138874



More information about the llvm-commits mailing list