llvm / llvm/llvm-project

[Mips] Redundant ANDI between FP comparison and integer SELNEZ on R6

Open
#224,542 1 comment 0 reactions 1 assignee Claimed by @FlyGoat View on GitHub
backend:MIPS missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

LVM emits an unnecessary `andi` when an R6 floating-point comparison controls an integer select.

`CMP.cond.S` produces an all-zero or all-one mask. After `MFC1`, this is already a valid condition for integer `SELNEZ`, which tests whether the GPR is nonzero.

### Reproducer
```llvm
define i32 @select_fp(float %a, float %b, i32 %value) {
%cond = fcmp olt float %a, %b
%result = select i1 %cond, i32 %value, i32 0
ret i32 %result
}
```

```sh
llc -mtriple=mipsel-linux-gnu -mcpu=mips32r6 -O2 \
-verify-machineinstrs repro.ll -o -
```

### Actual output
```asm
select_fp:
cmp.lt.s $f0, $f12, $f14
mfc1 $1, $f0
andi $1, $1, 1
jr $ra
selnez $2, $6, $1
```

### Expected output
```asm
select_fp:
cmp.lt.s $f0, $f12, $f14
mfc1 $1, $f0
jr $ra
selnez $2, $6, $1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.