This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR target/28946
- From: Rask Ingemann Lambertsen <rask at sygehus dot dk>
- To: Uros Bizjak <ubizjak at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 5 Sep 2006 17:08:53 +0200
- Subject: Re: [PATCH] Fix PR target/28946
- References: <5787cf470609050406q1846f74dk312431cafe456bf5@mail.gmail.com>
On Tue, Sep 05, 2006 at 01:06:58PM +0200, Uros Bizjak wrote:
> Hello!
>
> This patch fixes PR target/28946, a regression from gcc-2.95 (!)
>
> As desdribed in the PR, for following testcase:
>
> int fct1 (void);
> int fct2 (void);
>
> int
> fct (unsigned nb)
> {
> if ((nb >> 5) != 0)
> return fct1 ();
> else
> return fct2 ();
> }
>
> i386 backend emits spurious test instructions:
>
> fct:
> movl 4(%esp), %eax
> shrl $5, %eax
> testl %eax, %eax
> je .L2
> jmp fct1
> .p2align 4,,7
> .L2:
> jmp fct2
>
[snip proposed patch to combine]
> Resulting asm code is then:
>
> fct:
> movl 4(%esp), %eax
> shrl $5, %eax
> je .L2
> jmp fct1
> .p2align 4,,7
> .L2:
> jmp fct2
This is likely because you are missing a pattern in i386.md. You should
have something like this:
(define_insn "*lshrsi3_cconly"
[(set (reg:CC FLAGS_REG)
(compare:CC (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
(match_operand:QI 2 "nonmemory_operand" "Ci"))
(const_int 0)))
(clobber (match_scratch:SI 0 "=r"))]
""
"shrl %2, %0"
)
I have such a pattern in my experimental i8086 backend, and I get (for an an
i80186) with -dp:
fct:
pushw %bx ;# 65 *pushhi1
movw %sp, %bx ;# 63 *movhi/1
movw 4(%bx), %ax ;# 64 *movhi/1
shrw $5, %ax ;# 18 *lshrhi3_cconly_ccz/2
je .L2 ;# 19 *beq_ccz
call fct1 ;# 23 call_value
popw %bx ;# 68 *pophi1
ret ;# 69 *return
.L2:
call fct2 ;# 30 call_value
popw %bx ;# 75 *pophi1
ret ;# 76 *return
I.e. no spurious test instruction. The same applies to all arithmetic, logic
and shift/rotate instructions.
See also <URL:http://gcc.gnu.org/ml/gcc/2004-02/msg00903.html>.
--
Rask Ingemann Lambertsen