[llvm] [AArch64] Sink NOT to be fold into BIC/ORN/EON (PR #176194)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 20 07:58:19 PDT 2026


================
@@ -6845,6 +6845,50 @@ bool AArch64TTIImpl::isProfitableToSinkOperands(
     }
     break;
 
+  // Type            |    BIC    |    ORN    |    EON
+  // ----------------+-----------+-----------+-----------
+  // scalar          |    Base   |    Base   |    Base
+  // scalar w/shift  |     -     |     -     |     -
+  // fixed vector    | NEON/Base | NEON/Base | BSL2N/Base
+  // scalable vector |    SVE    |     -     |   BSL2N
+  case Instruction::Xor:
+    // EON only for scalars (possibly expanded fixed vectors)
+    // and vectors using the SVE2/SME BSL2N instruction.
+    if (I->getType()->isVectorTy() && ST->hasNEON() && !ST->hasSVE2() &&
+        !ST->hasSME())
+      break;
+    [[fallthrough]];
+  case Instruction::And:
+  case Instruction::Or:
+    // Even though we could use the SVE2/SME BSL2N instruction,
+    // it might pessimize with an extra MOV depending on register allocation.
+    if (I->getOpcode() == Instruction::Or &&
+        isa<ScalableVectorType>(I->getType()))
+      break;
+    // Shift can be fold into scalar AND/ORR/EOR,
+    // but not the non-negated operand of BIC/ORN/EON.
+    if (!(I->getType()->isVectorTy() && ST->hasNEON()) &&
----------------
pfusik wrote:

> I think you can't emit the vector instruction unless Neon is available.

Counter-example: https://godbolt.org/z/d3r9Tc68b
This is a vector instruction. Neon is not available.

> And if Neon availability is irrelevant, then couldn't the check be simplified just to !I->getType()->isVectorTy()?

Counter-example: https://godbolt.org/z/xY1YWfjWW
We have vector operations in LLVM IR. We only emit scalar instructions.

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


More information about the llvm-commits mailing list