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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 14:09:53 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;
----------------
goldsteinn wrote:

I think thats a mistake. If say we have `(select (icmp eq (or x, y), 0), (add x, 1), ...)`, we don't want to bail on simplifying the `add` just because its rhs is constant.

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


More information about the llvm-commits mailing list