Improve constant handling of thumb2 instructions
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Linaro GCC |
Fix Released
|
Undecided
|
Andrew Stubbs | ||
gcc |
Fix Released
|
Wishlist
|
Bug Description
This bug is reported in upstreams GCC, and the problem exists in Linaro GCC 4.5 also.
http://
Compile the following code with options -march=armv7-a -mthumb -Os
unsigned long tv(unsigned long x)
{
if (x >= 65521)
x = x - 65521;
return x;
}
gcc generates:
tv:
movw r3, #65520
cmp r0, r3
ittt hi
subhi r0, r0, #65024 // A
subhi r0, r0, #496 // B
subhi r0, r0, #1 // C
bx lr
Notice that (x = x - 65521) is translated into 3 instructions. Actually 65521
can be loaded into register with one instruction. So the shorter result is:
tv:
movw r3, #65520
cmp r0, r3
ittt hi
movwhi r1, #65521
subhi r0, r1
bx lr
This should be improved by function arm_gen_constant. The function is already
commented with
/* ??? This needs more work for thumb2. */
Related branches
- Richard Sandiford: Approve
- Linaro Toolchain Builder: Pending requested
-
Diff: 944 lines (+514/-202) (has conflicts)9 files modifiedChangeLog.linaro (+38/-0)
gcc/config/arm/arm-protos.h (+1/-0)
gcc/config/arm/arm.c (+297/-192)
gcc/config/arm/arm.md (+13/-9)
gcc/config/arm/constraints.md (+13/-1)
gcc/testsuite/gcc.target/arm/thumb2-replicated-constant1.c (+27/-0)
gcc/testsuite/gcc.target/arm/thumb2-replicated-constant2.c (+75/-0)
gcc/testsuite/gcc.target/arm/thumb2-replicated-constant3.c (+28/-0)
gcc/testsuite/gcc.target/arm/thumb2-replicated-constant4.c (+22/-0)
Changed in gcc-linaro: | |
assignee: | nobody → Andrew Stubbs (ams-codesourcery) |
status: | New → In Progress |
Changed in gcc: | |
importance: | Unknown → Medium |
status: | Unknown → In Progress |
tags: | added: speed |
Changed in gcc: | |
importance: | Medium → Wishlist |
status: | In Progress → Fix Released |
This bug is reported in upstreams GCC, and the problem exists in Linaro GCC 4.5 also. gcc.gnu. org/bugzilla/ show_bug. cgi?id= 46092
http://
Compile the following code with options -march=armv7-a -mthumb -Os
unsigned long tv(unsigned long x)
{
if (x >= 65521)
x = x - 65521;
return x;
}
gcc generates:
tv:
movw r3, #65520
cmp r0, r3
ittt hi
subhi r0, r0, #65024 // A
subhi r0, r0, #496 // B
subhi r0, r0, #1 // C
bx lr
Notice that (x = x - 65521) is translated into 3 instructions. Actually 65521
can be loaded into register with one instruction. So the shorter result is:
tv:
movw r3, #65520
cmp r0, r3
ittt hi
movwhi r1, #65521
subhi r0, r1
bx lr
This should be improved by function arm_gen_constant. The function is already
commented with
/* ??? This needs more work for thumb2. */