[llvm] [InstCombine] Pull extract through broadcast (PR #143380)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 14:10:20 PDT 2025


================
@@ -542,6 +542,13 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
         }
       }
     } else if (auto *SVI = dyn_cast<ShuffleVectorInst>(I)) {
+      // extractelt (shufflevector %v1, %v2, splat-mask) idx ->
+      // extractelt %v1, splat-mask[0]
+      auto Mask = SVI->getShuffleMask();
+      if (Mask[0] != PoisonMaskElem && all_equal(Mask))
----------------
agorenstein-nvidia wrote:

Thanks for catching that. With this and your other feedback, I'm seeing this transformation becoming more and more like the next case in the code (where the extract's constant is a known constant). That wasn't apparent to me at the beginning of the PR.

I'm exploring if there's a natural way to reframe this change as an extension to that prior work. I see in the docs that a mask's contents are either compile-time constants or poison, so using the just-found `llvm::getSplatIndex` (with care, it puns `not-found` and `poison`) we can basically reduce this new case to that the constant-index case. By that token, however, the constant case has some correctness concerns in the case of scalable vectors.

It is my EOD here, so I plan to return to this tomorrow with a refreshed look. Thanks again for all the quick and valuable feedback.

(I looked into the pipeline failures, the transformation kicked in more in related test files; I haven't closely examined the validity of those transformations yet, in light of the above.)

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


More information about the llvm-commits mailing list