[all-commits] [llvm/llvm-project] 4262ae: [LoongArch] Optimize conditional selection of integer

hev via All-commits all-commits at lists.llvm.org
Sun Jun 25 19:36:09 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4262ae20d8bd2247815d9417d69a63772af6a37f
      https://github.com/llvm/llvm-project/commit/4262ae20d8bd2247815d9417d69a63772af6a37f
  Author: Wang Rui <wangrui at loongson.cn>
  Date:   2023-06-26 (Mon, 26 Jun 2023)

  Changed paths:
    M llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
    M llvm/test/CodeGen/LoongArch/atomicrmw-uinc-udec-wrap.ll
    M llvm/test/CodeGen/LoongArch/ir-instruction/select-bare-int.ll

  Log Message:
  -----------
  [LoongArch] Optimize conditional selection of integer

This patch optimizes code generation by leveraging the zeroing behavior of the `maskeqz`/`masknez` instructions.

```
int sel(int a, int b)
{
    return (a < b) ? a : 0;
}
```

```
slt	$a1,$a0,$a1
masknez	$a2,$r0,$a1
maskeqz	$a0,$a0,$a1
or	$a0,$a0,$a2
```

=>

```
slt	$a1,$a0,$a1
maskeqz	$a0,$a0,$a1
```

Reviewed By: SixWeining

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




More information about the All-commits mailing list