[PATCH] D67875: [X86] X86DAGToDAGISel::matchBEXTRFromAndImm(): if can't use BEXTR, fallback to BZHI (PR43381)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 04:49:38 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: RKSimon, craig.topper, davezarzycki, spatel.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri edited the summary of this revision.

PR43381 notes that while we are good at matching `(X >> C1) & C2` as BEXTR/BEXTRI,
we only do that if we either have BEXTRI (TBM),
or if BEXTR is marked as being fast (`-mattr=+fast-bextr`).
In all other cases we don't match.

But that is mainly only true for AMD CPU's.
However, for all the CPU's for which we have sched models,
the BZHI is always fast (or the sched models are all bad.)

So if we decide that it's unprofitable to emit BEXTR/BEXTRI,
we should fall-back to BZHI if it is available,
and follow-up with the shift.

Indeed, BZHI does not have an immediate form,
but i think this is pretty identical to the BMI1 BEXTR situation.

(careful, i don't know much about intel cpu's my choice of `-mcpu` may be bad here)
Thus we manage to fold a load:
https://godbolt.org/z/Er0OQz
And if we don't, i think we still win some cycles:
https://godbolt.org/z/k6wFoz

https://bugs.llvm.org/show_bug.cgi?id=43381


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67875

Files:
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/test/CodeGen/X86/bmi-x86_64.ll
  llvm/test/CodeGen/X86/bmi.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67875.221167.patch
Type: text/x-patch
Size: 8805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190921/7393feae/attachment.bin>


More information about the llvm-commits mailing list