[GlobalISel] Combine (G_*ADDO x, 0) -> x + no carry out
authorJessica Paquette <jpaquette@apple.com>
Mon, 31 Jan 2022 22:13:18 +0000 (14:13 -0800)
committerJessica Paquette <jpaquette@apple.com>
Thu, 3 Feb 2022 22:25:15 +0000 (14:25 -0800)
commit9a61e731ff4c2b7e19438efa277b8712d4431b04
treedf40ec2a4c7d0cbad7a27d8aefd3f282b4d3b88f
parentc636899dc1fad6ecd0a1846d531df72fc7e76e22
[GlobalISel] Combine (G_*ADDO x, 0) -> x + no carry out

Similar to the G_*MULO change.

The code for checking if a constant is legal/pre-legalize is shared between
these, and is kind of hairy. So, factor it out into a new function:
`isConstantLegalOrBeforeLegalizer`.

To make the refactoring clean, further refactor `isLegalOrBeforeLegalizer` into
a wrapper for two functions:

- `isPreLegalize`
- `isLegal`

This is a bit easier to read in general.

https://godbolt.org/z/KW7oszP1o

Differential Revision: https://reviews.llvm.org/D118655
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
llvm/include/llvm/Target/GlobalISel/Combine.td
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/test/CodeGen/AArch64/GlobalISel/prelegalizer-combiner-addo-zero.mir [new file with mode: 0644]
llvm/test/CodeGen/AMDGPU/GlobalISel/saddsat.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/ssubsat.ll