[llvm] [InstSimplify] Use multi-op replacement when simplify `select` (PR #121708)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 13:43:04 PST 2025


================
@@ -4316,12 +4309,30 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
   if (isa<FreezeInst>(I))
     return nullptr;
 
+  SmallVector<std::pair<Value *, Value *>> ValidReplacements{};
+  for (const auto &OpAndRepOp : Ops) {
+    // We cannot replace a constant, and shouldn't even try.
+    if (isa<Constant>(OpAndRepOp.first))
+      return nullptr;
+
+    // For vector types, the simplification must hold per-lane, so forbid
+    // potentially cross-lane operations like shufflevector.
+    if (OpAndRepOp.first->getType()->isVectorTy() &&
+        !isNotCrossLaneOperation(I))
+      continue;
----------------
nikic wrote:

The const case should also return (as you already do).

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


More information about the llvm-commits mailing list