[llvm] [AArch64][SVE] Optimize logical ops with convert.to.svbool (PR #160408)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 06:01:05 PDT 2026


================
@@ -2014,6 +2014,34 @@ simplifySVEIntrinsicBinOp(InstCombiner &IC, IntrinsicInst &II,
   else
     SimpleII = simplifyBinOp(Opc, Op1, Op2, DL);
 
+  // If both operands are convert.to.svbool from the same narrower predicate
+  // type, try to simplify the operation at that narrower type. This is valid
+  // because the conversions zero the lanes not represented by the narrower
+  // type, so those lanes of the result are zero either way.
+  Value *NarrowOp1, *NarrowOp2;
+  if (!SimpleII &&
+      match(Op1, m_Intrinsic<Intrinsic::aarch64_sve_convert_to_svbool>(
+                     m_Value(NarrowOp1))) &&
+      match(Op2, m_Intrinsic<Intrinsic::aarch64_sve_convert_to_svbool>(
+                     m_Value(NarrowOp2))) &&
+      NarrowOp1->getType() == NarrowOp2->getType() &&
+      NarrowOp1->getType()->isScalableTy() &&
+      NarrowOp1->getType()->isIntOrIntVectorTy(1)) {
+    Value *SimpleNarrow = simplifyBinOp(Opc, NarrowOp1, NarrowOp2, DL);
+    if (SimpleNarrow && !isa<UndefValue>(SimpleNarrow)) {
+      if (match(SimpleNarrow, m_ZeroInt()))
+        SimpleII = Constant::getNullValue(II.getType());
+      else if (SimpleNarrow == NarrowOp1)
+        SimpleII = Op1;
+      else if (SimpleNarrow == NarrowOp2)
+        SimpleII = Op2;
+      else
+        SimpleII = IC.Builder.CreateIntrinsic(
+            Intrinsic::aarch64_sve_convert_to_svbool, {SimpleNarrow->getType()},
+            {SimpleNarrow});
----------------
paulwalker-arm wrote:

I believe you can drop the `{}` wrapping the type and operand and it will still work as expected.

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


More information about the llvm-commits mailing list