[llvm] [X86] Select standalone ~(-1 << n) masks as BZHI (PR #226158)

Chris Kennelly via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 08:02:41 PDT 2026


================
@@ -5818,6 +5819,10 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
     [[fallthrough]];
   case ISD::OR:
   case ISD::XOR:
+    // A standalone ~(-1 << n) mask is (-1 & lowmask(n)): mov -1; bzhi beats
+    // mov -1; shlx; not.
+    if (Opcode == ISD::XOR && Subtarget->hasBMI2() && matchBitExtract(Node))
+      return;
----------------
ckennelly wrote:

I moved `XOR` up to its own case, but the `Opcode==ISD::XOR` check is still necessary, I think, since we're falling through from above (`AND`).  I pushed cb3251b7c3a2963153be88503996b9a88c556e96 onto this PR, though.

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


More information about the llvm-commits mailing list