[all-commits] [llvm/llvm-project] 6ee306: [X86] Select standalone ~(-1 << n) masks as BZHI (...

Chris Kennelly via All-commits all-commits at lists.llvm.org
Mon Sep 28 02:19:32 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6ee306ddac89f9cbfc8815e8956240f0bf832dcb
      https://github.com/llvm/llvm-project/commit/6ee306ddac89f9cbfc8815e8956240f0bf832dcb
  Author: Chris Kennelly <ckennelly at ckennelly.com>
  Date:   2026-09-28 (Mon, 28 Sep 2026)

  Changed paths:
    M llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
    A llvm/test/CodeGen/X86/bzhi-standalone-mask.ll

  Log Message:
  -----------
  [X86] Select standalone ~(-1 << n) masks as BZHI (#226158)

InstCombine canonicalizes (1 << n) - 1 to xor (shl -1, n), -1. When that
mask feeds an AND, X86DAGToDAGISel::matchBitExtract folds the whole
expression into BZHI, and the add form is selected as BZHI even on its
own because Select enters matchBitExtract from ISD::ADD. The xor form on
its own is not: a mask that is returned, stored, or consumed by anything
but AND is selected as mov -1; shlx; not.

Enter matchBitExtract from ISD::XOR too under BMI2, so the standalone
mask becomes mov -1; bzhi. That is one instruction shorter and avoids
the shlx+not dependency chain. BMI1-only targets keep the shift form,
since BEXTR would need the count moved into bits 15:8 first.

Assisted-by: Claude Code



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list