[llvm] [AArch64][SVE] Optimize svand_z/svorr_z with all-true predicates. (PR #160408)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 05:51:25 PDT 2025


================
@@ -1643,6 +1679,15 @@ simplifySVEIntrinsicBinOp(InstCombiner &IC, IntrinsicInst &II,
   if (IInfo.inactiveLanesAreNotDefined())
     return IC.replaceInstUsesWith(II, SimpleII);
 
+  // For zeroing operations, if we have an all-true predicate and the result
+  // simplifies, we can just use the simplified result directly since there
+  // are no inactive lanes to worry about.
+  if (IInfo.inactiveLanesAreUnused() && isAllActivePredicate(Pg))
+    return IC.replaceInstUsesWith(II, SimpleII);
+
+  if (!IInfo.inactiveLanesTakenFromOperand())
+    return std::nullopt;
----------------
paulwalker-arm wrote:

This looks a bit wired.  In general I don't think you need to care about `Pg` being all true because `IInfo` already has enough information to know the result for inactive lanes. I think you want something more akin to:
```
if (IInfo.inactiveLanesTakenFromOperand)
  Inactive = II.getOperand(IInfo.getOperandIdxInactiveLanesTakenFrom());
else if (IInfo.inactiveLanesAreUnused() && IInfo.resultIsZeroInitialized())
  Inactive = Constant::getNullValue(SimpleII->getType());
else
  return nullptr;
```
Which means we'll simplify the transformation regardless of the predicate.  For the "all true" case the select will be redundant but I'd expect existing combines to handle that.

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


More information about the llvm-commits mailing list