OSDN Git Service

[AArch64][GlobalISel] Fold binops on the true side of G_SELECT
authorJessica Paquette <jpaquette@apple.com>
Tue, 8 Dec 2020 17:34:42 +0000 (09:34 -0800)
committerJessica Paquette <jpaquette@apple.com>
Tue, 8 Dec 2020 18:42:59 +0000 (10:42 -0800)
commitcd9a52b99e685e8a77dd85d25c7d1ec8b86b9f55
tree2e8285e408cc20981e82ea866291c4417211c1f1
parentce199667f65bcddc31c8c4be2b723f9132815fe6
[AArch64][GlobalISel] Fold binops on the true side of G_SELECT

This implements the following folds:

```
G_SELECT cc, (G_SUB 0, %x), %false -> CSNEG %x, %false, inv_cc
G_SELECT cc, (G_XOR x, -1), %false -> CSINV %x, %false, inv_cc
```

This is similar to the folds introduced in
5bc0bd05e6a8d788e08cdf3d154f3a33202aee53.

In 5bc0bd05e6a8d788e08cdf3d154f3a33202aee53 I mentioned that we may prefer to do
this in AArch64PostLegalizerLowering.

I think that it's probably better to do this in the selector. The way we select
G_SELECT depends on what register banks end up being assigned to it. If we did
this in AArch64PostLegalizerLowering, then we'd end up checking *every* G_SELECT
to see if it's worth swapping operands. Doing it in the selector allows us to
restrict the optimization to only relevant G_SELECTs.

Also fix up some comments in `TryFoldBinOpIntoSelect` which are kind of
confusing IMO.

Example IR: https://godbolt.org/z/3qPGca

Differential Revision: https://reviews.llvm.org/D92860
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/GlobalISel/select-select.mir