[PATCH] D68643: [Codegen] Alter the default promotion for saturating adds and subs

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 07:19:54 PDT 2019


dmgreen created this revision.
dmgreen added reviewers: RKSimon, efriedma, craig.topper, leonardchan.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: LLVM.

The default promotion for the add_sat/sub_sat nodes currently does:

  //   1. ANY_EXTEND iN to iM
  //   2. SHL by M-N
  //   3. [US][ADD|SUB]SAT
  //   4. L/ASHR by M-N

If the promoted add_sat or sub_sat node is not legal, this can produce code that effectively does a lot of shifting (and requiring large constants to be materialised) just to use the overflow flag. It is simpler to just do the saturation manually, using the higher bitwidth addition and a min/max against the saturating bounds. That is what this patch attempts to do.

A few points of interest:

- This still uses the existing promotion when the promoted add/sub_sat is legal. In many situations (but not all) it would probably be better to just perform the new promotion.
- It always creates a MIN and MAX node, even if they are not legal. The alternative would be to be to create a cmp/select pair, which these will legalise into anyway.
- We only have AArch64 and X86 tests. I have added ARM (for which just the differences are shown here). I'm happy to add other architectures if people are interested.


https://reviews.llvm.org/D68643

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  llvm/test/CodeGen/AArch64/sadd_sat.ll
  llvm/test/CodeGen/AArch64/sadd_sat_vec.ll
  llvm/test/CodeGen/AArch64/ssub_sat.ll
  llvm/test/CodeGen/AArch64/ssub_sat_vec.ll
  llvm/test/CodeGen/AArch64/uadd_sat.ll
  llvm/test/CodeGen/AArch64/uadd_sat_vec.ll
  llvm/test/CodeGen/AArch64/usub_sat.ll
  llvm/test/CodeGen/AArch64/usub_sat_vec.ll
  llvm/test/CodeGen/ARM/sadd_sat.ll
  llvm/test/CodeGen/ARM/ssub_sat.ll
  llvm/test/CodeGen/ARM/uadd_sat.ll
  llvm/test/CodeGen/ARM/usub_sat.ll
  llvm/test/CodeGen/X86/sadd_sat.ll
  llvm/test/CodeGen/X86/ssub_sat.ll
  llvm/test/CodeGen/X86/uadd_sat.ll
  llvm/test/CodeGen/X86/usub_sat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68643.223836.patch
Type: text/x-patch
Size: 65749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191008/7213aecc/attachment-0001.bin>


More information about the llvm-commits mailing list