https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111252
Bug ID: 111252
Summary: LoongArch: Suboptimal code for (a & ~mask) | (b &
mask) where mask is a constant with value ((1 << n) -
1) << m
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
int test(int a, int b)
{
return (a & ~0x10) | (b & 0x10);
}
compiles to:
addi.w $r12,$r0,-17 # 0xffffffffffffffef
and $r12,$r12,$r4
andi $r5,$r5,16
or $r12,$r12,$r5
slli.w $r4,$r12,0
jr $r1
It should be improved:
bstrpick.w $r4, $r4, 4, 4
bstrins.w $r5, $r4, 4, 4
or $r5, $r4, $r0