https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123838
Bug ID: 123838
Summary: riscv: Optimize int shift left by (31 - n).
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization
Severity: enhancement
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: rdapp at gcc dot gnu.org
CC: law at gcc dot gnu.org
Target Milestone: ---
Target: riscv
Similar to PR123792 for aarch64, we could do better at
int f1 (int x, int n)
{
return x << (31 - n);
}
and related.
Currently:
li a5,31
subw a5,a5,a1
sllw a0,a0,a5
ret
clang:
not a1, a1
sllw a0, a0, a1
ret
It feels like we should already have a similar bug but I didn't find one.