https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106585
Bug ID: 106585
Summary: RISC-V: Mis-optimized code gen for zbs
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kito at gcc dot gnu.org
Target Milestone: ---
Target: riscv
Command:
$ riscv64-unknown-elf-gcc foo.c -o - -S -O3 -march=rv64imafdc_zbb_zbs
```c
int foo(int rs1, int rs2) {
return (rs1 & ~(1<<rs2));
}
```
Current code gen:
```asm
foo:
li a5,1
sllw a5,a5,a1
andn a0,a0,a5
sext.w a0,a0
ret
```
And even worth if compile without zbb
```asm
foo:
li a5,1
sllw a5,a5,a1
andn a0,a0,a5
sext.w a0,a0
ret
```
clang code gen:
```
foo:
bclr a0, a0, a1
sext.w a0, a0
ret
```