[llvm] ValueTracking: introduce llvm::isLanewiseOperation (PR #112011)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 06:33:39 PDT 2024


================
@@ -6947,6 +6947,81 @@ bool llvm::onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V) {
       V, /* AllowLifetime */ true, /* AllowDroppable */ true);
 }
 
+bool llvm::isLanewiseOperation(const Instruction *I) {
+  if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+    switch (II->getIntrinsicID()) {
+    // TODO: expand this list.
+    case Intrinsic::abs:
+    case Intrinsic::smax:
+    case Intrinsic::smin:
+    case Intrinsic::umax:
+    case Intrinsic::umin:
+    case Intrinsic::sqrt:
+    case Intrinsic::powi:
+    case Intrinsic::sin:
+    case Intrinsic::cos:
+    case Intrinsic::tan:
+    case Intrinsic::asin:
+    case Intrinsic::acos:
+    case Intrinsic::atan:
+    case Intrinsic::atan2:
+    case Intrinsic::sinh:
+    case Intrinsic::cosh:
+    case Intrinsic::tanh:
+    case Intrinsic::pow:
+    case Intrinsic::exp:
+    case Intrinsic::exp2:
+    case Intrinsic::exp10:
+    case Intrinsic::ldexp:
+    case Intrinsic::frexp:
+    case Intrinsic::log:
+    case Intrinsic::log10:
+    case Intrinsic::log2:
+    case Intrinsic::fma:
+    case Intrinsic::fabs:
+    case Intrinsic::minimum:
+    case Intrinsic::maximum:
+    case Intrinsic::minimumnum:
+    case Intrinsic::maximumnum:
+    case Intrinsic::copysign:
+    case Intrinsic::floor:
+    case Intrinsic::ceil:
+    case Intrinsic::trunc:
+    case Intrinsic::rint:
+    case Intrinsic::nearbyint:
+    case Intrinsic::round:
+    case Intrinsic::roundeven:
+    case Intrinsic::lround:
+    case Intrinsic::llround:
+    case Intrinsic::lrint:
+    case Intrinsic::llrint:
+    case Intrinsic::bitreverse:
+    case Intrinsic::bswap:
+    case Intrinsic::ctpop:
+    case Intrinsic::ctlz:
+    case Intrinsic::cttz:
+    case Intrinsic::fshl:
+    case Intrinsic::fshr:
+    case Intrinsic::usub_sat:
+    case Intrinsic::uadd_sat:
+    case Intrinsic::ushl_sat:
+    case Intrinsic::ssub_sat:
+    case Intrinsic::sadd_sat:
+    case Intrinsic::sshl_sat:
+    case Intrinsic::canonicalize:
+    case Intrinsic::fmuladd:
+    case Intrinsic::fptoui_sat:
+    case Intrinsic::fptosi_sat:
+      return true;
+    default:
+      return false;
+    }
+  }
+  auto *Shuffle = dyn_cast<ShuffleVectorInst>(I);
+  return (!Shuffle || Shuffle->isIdentity() || Shuffle->isSelect()) &&
----------------
nikic wrote:

Wouldn't an identity shuffle be optimized out? Let's not add these shufflevector checks if there is no use case.

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


More information about the llvm-commits mailing list