[Codegen] Alter the default promotion for saturating adds and subs
commiteaef0d10bd32da2784113cc766fc205be2da5c11
authorDavid Green <david.green@arm.com>
Fri, 18 Oct 2019 09:47:48 +0000 (18 09:47 +0000)
committerDavid Green <david.green@arm.com>
Fri, 18 Oct 2019 09:47:48 +0000 (18 09:47 +0000)
tree28d6ef6f6d9230ed13b1de4280d87025d7465175
parent9d9055cfe2e0e8a48be86cf935b1d8399e043586
[Codegen] Alter the default promotion for saturating adds and subs

The default promotion for the add_sat/sub_sat nodes currently does:
    ANY_EXTEND iN to iM
    SHL by M-N
    [US][ADD|SUB]SAT
    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.

Differential Revision: https://reviews.llvm.org/D68926

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375211 91177308-0d34-0410-b5e6-96231b3b80d8
29 files changed:
lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
test/CodeGen/AArch64/sadd_sat.ll
test/CodeGen/AArch64/sadd_sat_plus.ll
test/CodeGen/AArch64/sadd_sat_vec.ll
test/CodeGen/AArch64/ssub_sat.ll
test/CodeGen/AArch64/ssub_sat_plus.ll
test/CodeGen/AArch64/ssub_sat_vec.ll
test/CodeGen/AArch64/uadd_sat.ll
test/CodeGen/AArch64/uadd_sat_plus.ll
test/CodeGen/AArch64/uadd_sat_vec.ll
test/CodeGen/AArch64/usub_sat.ll
test/CodeGen/AArch64/usub_sat_plus.ll
test/CodeGen/AArch64/usub_sat_vec.ll
test/CodeGen/ARM/sadd_sat.ll
test/CodeGen/ARM/sadd_sat_plus.ll
test/CodeGen/ARM/ssub_sat.ll
test/CodeGen/ARM/ssub_sat_plus.ll
test/CodeGen/ARM/uadd_sat.ll
test/CodeGen/ARM/uadd_sat_plus.ll
test/CodeGen/ARM/usub_sat.ll
test/CodeGen/ARM/usub_sat_plus.ll
test/CodeGen/X86/sadd_sat.ll
test/CodeGen/X86/sadd_sat_plus.ll
test/CodeGen/X86/ssub_sat.ll
test/CodeGen/X86/ssub_sat_plus.ll
test/CodeGen/X86/uadd_sat.ll
test/CodeGen/X86/uadd_sat_plus.ll
test/CodeGen/X86/usub_sat.ll
test/CodeGen/X86/usub_sat_plus.ll