[llvm] [VectorCombine] Fold ZExt/SExt (Shuffle (ZExt/SExt %src)) to ZExt/SExt (Shuffle %src). (PR #141109)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 07:28:12 PDT 2025


https://github.com/fhahn commented:

> > > ```
> > > 2. All of your tests appear to use identity shuffles.  Those can just be removed.  Once that's done, we have two adjacent extends, which should already be handled?  Either your tests need updated, or there's something off here?
> > > ```
> > 
> > 
> > I may be missing something, but the shuffles are needed to extract half the vector elements. In the current version, I create a new shuffle of the narrower vector type, which is trivially fold-able by instcombine for the test cases.
> 
> Ah, I'd missed these were length changing shuffles.
> 
> Another high level question for you. Could we phrase this as a generic shuffle placement canonicalization? If my memory serves, we generally push truncates early, and extends late in instcombine. What would you think of an analogous canonicalization for narrowing and widening shuffles? In this particular case, it would group the extends together, and then let generic extend combines merge them.

Thanks for the suggestion, it looks like we already move some casts across shuffles, so it seems like this might be a good fit: https://github.com/llvm/llvm-project/pull/146901

https://github.com/llvm/llvm-project/pull/141109


More information about the llvm-commits mailing list