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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri May 30 03:14:07 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) &&
----------------
dtcxzyw wrote:

If the call base has `noundef` on the return value, it is not safe to be speculatively executed.



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


More information about the llvm-commits mailing list