[DAGCombiner][RISCV] Pre-promote (zext (abs X)) to (abs (sext X)) when X has an illeg...
authorCraig Topper <craig.topper@sifive.com>
Fri, 13 Jan 2023 18:04:00 +0000 (10:04 -0800)
committerCraig Topper <craig.topper@sifive.com>
Fri, 13 Jan 2023 18:40:25 +0000 (10:40 -0800)
commitc8bd5343df642f98966cea7aabc6b26144ec87e1
tree14d7364acf078d7531701deaa3ac375767d13ff0
parent8b7c1fbd9647a5a6ef246a6b5b2543ea0f5a2337
[DAGCombiner][RISCV] Pre-promote (zext (abs X)) to (abs (sext X)) when X has an illegal type.

Type legalization will insert a sign extend anyway. By doing it
early we can remove the zext. ComputeNumSignBits can't spot it
after type legalization because type legalization may expand
the abs to sra+xor+sub.

If the zext result type is larger than the type to be promoted to,
we'll promote to a legal type and then zext the rest of the way.
If the legal type is larger than the destination type we can promote
and then truncate.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D140509
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/iabs.ll