[llvm] [AArch64][SVE2] Allow commuting two-input NBSL/BSL2N idioms. (PR #184847)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 02:20:22 PST 2026


================
@@ -4147,6 +4147,22 @@ let Predicates = [HasSVE2_or_SME] in {
   defm BSL2N_ZZZZ : sve2_int_bitwise_ternary_op<0b101, "bsl2n", AArch64bsl2n>;
   defm NBSL_ZZZZ  : sve2_int_bitwise_ternary_op<0b111, "nbsl",  AArch64nbsl>;
 
+  // Pseudos for commutable operations that expand to NBSL or BSL2N. These can
+  // avoid a COPY if one of the source registers can be clobbered.
+  let isCommutable = 1, hasSideEffects = 0 in {
+    // EON (a, b) = BSL2N (a, a, b) = BSL2N (b, b, a)
+    def EON_ZZZ : Pseudo<(outs ZPR64:$Zdn), (ins ZPR64:$_Zdn, ZPR64:$Zm), [], "$Zdn = $_Zdn">,
+                  PseudoInstExpansion<(BSL2N_ZZZZ ZPR64:$Zdn, ZPR64:$_Zdn, ZPR64:$_Zdn, ZPR64:$Zm)>;
----------------
pfusik wrote:

#176194 is not urgent. Choose the best long-term solution. `MOVPRFX` would be great. Reordering the operands of `BSL2N_ZZZZ` later seems cleaner than introducing extra pseudos such as `EON_ZZZ`.

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


More information about the llvm-commits mailing list