[llvm] [VectorCombine] Scalarize bin ops and cmps with two splatted operands (PR #137786)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 11:20:06 PDT 2025


preames wrote:

Couple of high level comments:

1) Your description on the review is a bit misleading.  You're not adjusting a transform which matches the instcombine canonicalized splat idiom, you're adjusting one which only handles the insert/binop part.  (That is, it never sees the splat.)  As a result, your change isn't *just* for constants, it's really adding splat handling over all.  We might expect the extra generality to be rarely hit, but we should have tests, etc..  

Honestly, I think this pushes thing in the direction of a new transform, but I'm open to being convinced I'm wrong there.  Note that scalarizeVPIntrinsic does exactly the proposed transform, but only for VP.  I don't see obvious code sharing there, but maybe there's something?

If you do want to take the single transform route, please make sure you update the block comments.  

2) Looking at this code snippet:
```
   %x.insert = insertelement <vscale x 4 x i32> poison, i32 %x, i64 0
    %x.splat = shufflevector <vscale x 4 x i32> %x.insert, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
    %res = add <vscale x 4 x i32> %x.splat, splat (i32 42)
```

This looks like a missing case in the shuffle canonicalization done by InstCombine in foldVectorBinop.  We should be able to convert this to:
```
   %x.insert = insertelement <vscale x 4 x i32> poison, i32 %x, i64 0
    %add = add <vscale x 4 x i32> %x, splat (i32 42)
    %res = shufflevector <vscale x 4 x i32> %add, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
```

In fact, I'm confused why the block which starts with "If one argument is a shuffle within one vector and the other is a constant" doesn't transform this case.  

Now, I'm not really sure that's a good canonicalization overall (since it breaks the splat recognition), but why isn't the instcombine code able to handle this?




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


More information about the llvm-commits mailing list