This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
cse optiming
- To: gcc at gcc dot gnu dot org
- Subject: cse optiming
- From: Herman ten Brugge <Haj dot Ten dot Brugge at net dot HCC dot nl>
- Date: Wed, 5 Jan 2000 21:32:26 +0000 (WET)
Hello,
I discovered some strange effects of cse. I was assuming that gcc was
clever enough to optimize the routines at the bottum of this mail to the
same code.
This is not the case for example on the sparc. The code for tst1 is
optimized correctly into a shift and an add insn. The tst3 and tst4 use
the umul to do the same thing.
The problem is that cse calls simplify_rtx to simplify the expr_list
from the following insn (see line 7205 cse.c).
(insn 19 17 21 (set (reg:SI 109)
(reg:SI 8 %o0)) 105 {*movsi_insn} (nil)
(insn_list:REG_RETVAL 14 (expr_list:REG_EQUAL (mult:SI (reg/v:SI 106)
(const_int 3 [0x3]))
(nil))))
simplify_rtx can not generate new registers so it can not call expand_mult in
expmed.c which would do the correct thing (see tst1).
The same problem also occurs for other library calls. I first discovered
this problem on the c4x with a divide insn.
Is there a cure for this problem?
Herman.
c-code:
-------------------------------------------
unsigned
tst1(unsigned a)
{
return a * 3;
}
static inline unsigned
tst2(unsigned a, unsigned b)
{
return a * b;
}
unsigned
tst3(unsigned p)
{
return tst2(p,3);
}
unsigned
tst4(unsigned p)
{
unsigned int a = 3;
return p * a;
}
asm-code: (-O3 on sparc)
-------------------------------------------
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 4
.global _tst1
.proc 016
_tst1:
!#PROLOGUE# 0
!#PROLOGUE# 1
sll %o0, 1, %g2
retl
add %g2, %o0, %o0
.align 4
.global _tst3
.proc 016
_tst3:
!#PROLOGUE# 0
save %sp, -104, %sp
!#PROLOGUE# 1
mov %i0, %o0
call .umul, 0
mov 3, %o1
ret
restore %g0, %o0, %o0
.align 4
.global _tst4
.proc 016
_tst4:
!#PROLOGUE# 0
save %sp, -104, %sp
!#PROLOGUE# 1
mov %i0, %o0
call .umul, 0
mov 3, %o1
ret
restore %g0, %o0, %o0