llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.04k stars 11.98k forks source link

[DAGCombine] Use SelectionDAG::computeOverflowKind to relax ADD/SUB S/US nodes to generic ADD/SUB #37110

Closed RKSimon closed 1 year ago

RKSimon commented 6 years ago
Bugzilla Link 37762
Version trunk
OS Windows NT
CC @topperc,@deadalnix,@LebedevRI,@nikic,@rotateright
Fixed by commit(s) 351026,351057

Extended Description

If the saturated nodes are guaranteed not to overflow then they should become generic ADD/SUB nodes. As a stretch goal the HADDS/HSUBS cases could be handled as well.

Many CPUs can perform the saturated forms only on some ports, or at a lower perf.

RKSimon commented 5 years ago

The add/sub saturated instruction are now generic opcodes, InstCombine already does this pretty thoroughly but we need to add at least basic support in DAGCombine as we can create these nodes there as well.

ISD::UADDSAT was added at rL351026 (with a bugfix for ISD::SADDAT at rL351057).

RKSimon commented 1 year ago

Resolving - visitADDSAT/visitSUBSAT use the willNotOverflowAdd/willNotOverflowSub helpers to relax to regular ADD/SUB - 56ba1db933ea / 3fb067f7ba8e / 8f82d8ee7603

X86 doesn't do anything with the HADDS/HSUBS instructions, so that can be left as a future x86-specific issue if a need arises.