[llvm] [InstCombine] Fold shuffles through all trivially vectorizable intrinsics (PR #141979)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri May 30 04:27:33 PDT 2025


================
@@ -1401,26 +1401,25 @@ static Instruction *factorizeMinMaxTree(IntrinsicInst *II) {
 /// try to shuffle after the intrinsic.
 Instruction *
 InstCombinerImpl::foldShuffledIntrinsicOperands(IntrinsicInst *II) {
-  // TODO: This should be extended to handle other intrinsics like fshl, ctpop,
-  //       etc. Use llvm::isTriviallyVectorizable() and related to determine
-  //       which intrinsics are safe to shuffle?
-  switch (II->getIntrinsicID()) {
-  case Intrinsic::smax:
-  case Intrinsic::smin:
-  case Intrinsic::umax:
-  case Intrinsic::umin:
-  case Intrinsic::fma:
-  case Intrinsic::fshl:
-  case Intrinsic::fshr:
-    break;
-  default:
+  if (!isTriviallyVectorizable(II->getIntrinsicID()))
+    return nullptr;
+
+  assert(isSafeToSpeculativelyExecute(II) &&
----------------
lukel97 wrote:

Should this be turned into just a check then? I could imagine at some point we might want to mark e.g. `udiv.fix` as trivially vectorizable even if it's not speculatable. In which case we would not be able to perform this combine.

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


More information about the llvm-commits mailing list