public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/8848: g++ 3.3: bad code when optimizing (lifetime analysis pass?)
@ 2002-12-06 12:56 snyder
  0 siblings, 0 replies; only message in thread
From: snyder @ 2002-12-06 12:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8848
>Category:       optimization
>Synopsis:       g++ 3.3: bad code when optimizing (lifetime analysis pass?)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 06 12:56:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     scott snyder
>Release:        3.3 20021203 (experimental)
>Organization:
>Environment:
System: Linux karma 2.4.19-emp_2419p5a829i #1 Tue Sep 3 17:42:17 EST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77
>Description:

The following program is miscompiled in linux/x86 when the
`-march=pentium2 -O1' flags are used.

I expect this program to print `3 3'; here's what it actually does:

$ g++ -o x -march=pentium2 -O1 x.cc
$ ./x
0 3
$

Here's the relevant portion of the generated code:

	movl	8(%ebp), %ecx  ; status -> ecx
	cmpl	$1, %ecx
	sete	%al
	movzbl	%al, %edx
	cmpl	$4, %ecx
	movl	$3, %eax
	cmove	%eax, %edx
	movl	$4, %eax
	cmove	%eax, %edx
	movl	%ecx, 8(%esp)   ; status
	movl	%edx, 4(%esp)   ; s
	movl	$.LC0, (%esp)
	call	printf

It looks like the comparison against `3' has been dropped.

Looking at the RTL dumps, it looks like things are going
bad during the lifetime analysis pass.

In the `bp' dump (whatever that is --- it would be incredibly useful
if the `passes' section of the documentation were kept up to date),
i see comparisons against 1, 3, and 4.  But in the `life' dump,
i see comparisions against 1, 4, and 4:

(insn 3 56 4 0 (nil) (set (reg/v:SI 58)
        (mem/f:SI (reg/f:SI 16 argp) [0 status+0 S4 A32])) 38 {*movsi_1} (nil)
    (expr_list:REG_EQUIV (mem/f:SI (reg/f:SI 16 argp) [0 status+0 S4 A32])
        (nil)))

(note 4 3 64 0 NOTE_INSN_FUNCTION_BEG)

(insn 64 4 65 0 0x400439cc (set (reg:CCZ 17 flags)
        (compare:CCZ (reg/v:SI 58)
            (const_int 1 [0x1]))) -1 (insn_list 3 (nil))
    (nil))

(insn 65 64 67 0 0x400439cc (set (reg:QI 60)
        (eq:QI (reg:CCZ 17 flags)
            (const_int 0 [0x0]))) -1 (insn_list 64 (nil))
    (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (nil)))

(insn 67 65 69 0 0x400439cc (parallel [
            (set (reg:SI 61)
                (zero_extend:SI (reg:QI 60)))
            (clobber (reg:CC 17 flags))
        ]) 84 {*zero_extendqisi2_movzbw_and} (insn_list 65 (nil))
    (expr_list:REG_DEAD (reg:QI 60)
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

(insn 69 67 37 0 0x400439cc (set (reg:SI 62)
        (const_int 3 [0x3])) -1 (nil)
    (expr_list:REG_EQUAL (const_int 3 [0x3])
        (nil)))

(insn 37 69 71 0 0x400439cc (set (reg:CCZ 17 flags)
        (compare:CCZ (reg/v:SI 58)
            (const_int 4 [0x4]))) 2 {*cmpsi_1_insn} (nil)
    (nil))

(insn 71 37 73 0 0x400439cc (set (reg:SI 63)
        (if_then_else:SI (ne (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (reg:SI 61)
            (reg:SI 62))) 462 {*movsicc_noc} (insn_list 67 (insn_list 69 (insn_list 37 (nil))))
    (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (expr_list:REG_DEAD (reg:SI 61)
            (expr_list:REG_DEAD (reg:SI 62)
                (nil)))))

(insn 73 71 72 0 0x400439cc (set (reg:SI 64)
        (const_int 4 [0x4])) -1 (nil)
    (expr_list:REG_EQUAL (const_int 4 [0x4])
        (nil)))

(insn 72 73 74 0 0x400439cc (set (reg:CCZ 17 flags)
        (compare:CCZ (reg/v:SI 58)
            (const_int 4 [0x4]))) -1 (nil)
    (nil))

(insn 74 72 48 0 0x400439cc (set (reg/v:SI 59)
        (if_then_else:SI (ne (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (reg:SI 63)
            (reg:SI 64))) -1 (insn_list 71 (insn_list 73 (insn_list 72 (nil))))
    (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (expr_list:REG_DEAD (reg:SI 63)
            (expr_list:REG_DEAD (reg:SI 64)
                (nil)))))

(insn 48 74 49 0 0x400439cc (set (mem/f:SI (plus:SI (reg/f:SI 7 esp)
                (const_int 8 [0x8])) [0 S4 A32])
        (reg/v:SI 58)) 38 {*movsi_1} (nil)
    (expr_list:REG_DEAD (reg/v:SI 58)
        (nil)))

(insn 49 48 50 0 0x400439cc (set (mem/f:SI (plus:SI (reg/f:SI 7 esp)
                (const_int 4 [0x4])) [0 S4 A32])
        (reg/v:SI 59)) 38 {*movsi_1} (insn_list 74 (nil))
    (expr_list:REG_DEAD (reg/v:SI 59)
        (nil)))

(insn 50 49 51 0 0x400439cc (set (mem/f:SI (reg/f:SI 7 esp) [0 S4 A32])
        (symbol_ref/f:SI ("*.LC0"))) 38 {*movsi_1} (nil)
    (nil))




>How-To-Repeat:

Compile this with with `-march=pentium2 -O1':

--------------------------------
extern "C" int printf (const char*, ...);

void set_parameters_nocache(int status) {
  int s = 0;
  if( status == 1 ) s=1;
  if( status == 3 ) s=3;
  if( status == 4 ) s=4;

  printf ("%d %d\n", s, status);
}



int main( ) {
  set_parameters_nocache (3);
}


--------------------------------

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-12-06 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 12:56 optimization/8848: g++ 3.3: bad code when optimizing (lifetime analysis pass?) snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).