[PATCH] D48789: [X86] Replace (32/64 - n) shift amounts with (neg n) since the shift amount is masked in hardware

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 29 14:34:00 PDT 2018


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, lebedev.ri.
Herald added a reviewer: javed.absar.
Herald added a subscriber: kristof.beyls.

Inspired by what AArch64 does for shifts, this patch attempts to replace shift amounts with neg if we can.

This is done directly as part of isel so its as late as possible to avoid breaking some BZHI patterns since those patterns need an unmasked (32-n) to be correct.

To avoid manual load folding and custom instruction selection for the negate. I've inserted new nodes in the DAG above the shift node in topological order. Though as I'm writing this, I'm wondering if it might make more sense to put them above the original shift amount node instead. By inserting them in the topogical order we should be able to run isel on them independently.

This patch does risk leaving behind a subtract and creating a negate if the subtract was used by something other than a shift.


https://reviews.llvm.org/D48789

Files:
  lib/Target/X86/X86ISelDAGToDAG.cpp
  test/CodeGen/X86/extract-lowbits.ll
  test/CodeGen/X86/schedule-x86-64-shld.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48789.153571.patch
Type: text/x-patch
Size: 23795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180629/6ae7b4d7/attachment.bin>


More information about the llvm-commits mailing list