[PATCH] D97397: [InstCombine] Add a combine for a shuffle of identical bitcasts

Sanne Wouda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 09:43:08 PST 2021


sanwou01 added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:2297
+  Value *X, *Y;
+  if (match(LHS, m_BitCast(m_Value(X))) && match(RHS, m_BitCast(m_Value(Y))) &&
+      X->getType()->isVectorTy() &&
----------------
lebedev.ri wrote:
> One of the original bitcasts needs to be one-use, else we'll increase instruction count.
Good point! I can bail out if neither is one-use.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:2299
+      X->getType()->isVectorTy() &&
+      cast<FixedVectorType>(X->getType())->getNumElements() == VWidth &&
+      X->getType() == Y->getType()) {
----------------
lebedev.ri wrote:
> Can we do anything for the case where we have element count mismatches?
Yes, I'm being fairly conservative here. I think the following example would be legal to transform similarly. Is that what you had in mind?

```
%0 = bitcast <4 x i32> %a to <4 x float>
%1 = bitcast <2 x i32> %b to <2 x float>
%2 = shufflevector <4 x float> %0, <2 x float> %1, <2 x i32> <i32 3, i32 5>
```


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:2301
+      X->getType() == Y->getType()) {
+    Value *V = Builder.CreateShuffleVector(X, Y, SVI.getShuffleMask());
+    return new BitCastInst(V, SVI.getType());
----------------
lebedev.ri wrote:
> 
Nice, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97397



More information about the llvm-commits mailing list