public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13313] New: Wrong code generated
@ 2003-12-05 12:10 mike at ml-solutions dot co dot uk
  2003-12-05 12:42 ` [Bug c/13313] " bangerth at dealii dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: mike at ml-solutions dot co dot uk @ 2003-12-05 12:10 UTC (permalink / raw)
  To: gcc-bugs

When the following code is compiled
---------------------
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"

extern void DisplayNumber (unsigned long);
unsigned long ReadNumber ()
{
 return 8L;
}

void test_a (void)
{
 unsigned long tmp;
 tmp = (ReadNumber() & 0x00ff0000L) >> 16;
 DisplayNumber (tmp);
}
------------------------------------------

The code generated for the test_a function is incorrect.

The compiler is mainline CVS built on 20031127 

Compiler command line was 
h8300-hitachi-elf-gcc -v --save-temps -Wall -I include -Wa,-a=test.lst  -
gstabs -O1 -finline -c test.c

Compiler was configured as 
/home/administrator/h8-build/src2/configure --build=i686-pc-cygwin --host=i686-
pc-cygwin --target=h8300-hitachi-elf --with-included-gettext --disable-
libstdcxx_pch --enable-multilib

-- 
           Summary: Wrong code generated
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mike at ml-solutions dot co dot uk
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: h8300-hitachi-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
@ 2003-12-05 12:42 ` bangerth at dealii dot org
  2003-12-05 13:15 ` mike at ml-solutions dot co dot uk
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2003-12-05 12:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2003-12-05 12:42 -------
What exactly do you mean by "wrong code is produced"? Can you post
assembler code and show where you believe it is wrong?

Thanks
  Wolfgang

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
  2003-12-05 12:42 ` [Bug c/13313] " bangerth at dealii dot org
@ 2003-12-05 13:15 ` mike at ml-solutions dot co dot uk
  2003-12-06  4:35 ` [Bug optimization/13313] " pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mike at ml-solutions dot co dot uk @ 2003-12-05 13:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mike at ml-solutions dot co dot uk  2003-12-05 13:15 -------
Assembler generated is as follows

_test_a:
	mov.w	r6,@-r7
	mov.w	r7,r6
	jsr	@_ReadNumber
	mov.b	#0,r1h
	sub.w	r0,r0
	jsr	@_DisplayNumber
	mov.w	@r7+,r6
	rts

The code immediately after the return from readnumber should have been

    mov.b   r0l,r1l        <----- this is the missing line
    mov.b   #0,r1h
    sub.w   r0,r0




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug optimization/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
  2003-12-05 12:42 ` [Bug c/13313] " bangerth at dealii dot org
  2003-12-05 13:15 ` mike at ml-solutions dot co dot uk
@ 2003-12-06  4:35 ` pinskia at gcc dot gnu dot org
  2003-12-06  7:36 ` [Bug target/13313] " pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-06  4:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-06 04:35 -------
Confirmed, combine is the pass which is making this bad code.
From:
(insn 10 9 12 0 (set (reg:SI 17)
        (reg:SI r0)) 11 {*movsi_h8300} (insn_list 9 (nil))
    (expr_list:REG_DEAD (reg:SI r0)
        (insn_list:REG_RETVAL 9 (expr_list:REG_EQUAL (expr_list (symbol_ref:HI ("ReadNumber") [flags 
0x3] <function_decl 0x40d9e4a4 ReadNumber>)
                    (nil))
                (nil)))))

(insn 12 10 16 0 (set (reg/v:SI 16 [ tmp ])
        (and:SI (reg:SI 17)
            (const_int 16711680 [0xff0000]))) 61 {*logicalsi3} (insn_list 10 (nil))
    (expr_list:REG_DEAD (reg:SI 17)
        (nil)))

(insn 16 12 19 0 (parallel [
            (set (reg:SI 18 [ tmp ])
                (lshiftrt:SI (reg/v:SI 16 [ tmp ])
                    (const_int 16 [0x10])))
            (clobber (scratch:QI))
        ]) 114 {*shiftsi} (insn_list 12 (nil))
    (expr_list:REG_DEAD (reg/v:SI 16 [ tmp ])
        (expr_list:REG_UNUSED (scratch:QI)
            (expr_list:REG_EQUAL (lshiftrt:SI (reg/v:SI 16 [ tmp ])
                    (const_int 16 [0x10]))
                (nil)))))

(insn 19 16 20 0 (set (reg:SI r0 [ tmp ])
        (reg:SI 18 [ tmp ])) 11 {*movsi_h8300} (insn_list 16 (nil))
    (expr_list:REG_DEAD (reg:SI 18 [ tmp ])
        (nil)))
To:

(insn 19 16 20 0 (set (reg:SI r0 [ tmp ])
        (zero_extend:SI (reg:QI r1 [orig:0+3 ] [0]))) 102 {*zero_extendqisi2_h8300} (insn_list 9 (nil))
    (nil))

Is this a regression?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal
             Status|WAITING                     |NEW
          Component|c                           |optimization
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2003-12-06 04:35:46
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (2 preceding siblings ...)
  2003-12-06  4:35 ` [Bug optimization/13313] " pinskia at gcc dot gnu dot org
@ 2003-12-06  7:36 ` pinskia at gcc dot gnu dot org
  2003-12-08 14:29 ` mike at ml-solutions dot co dot uk
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-06  7:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-06 07:36 -------
Actually combine is doing the right thing (expect for the target being wrong).
The problem is in the target.
I do not how to solve this problem but it is related to the pattern for zero_extendqisi2_h8300:
(define_insn "*zero_extendqisi2_h8300"
  [(set (match_operand:SI 0 "register_operand" "=r,r")
        (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
  "TARGET_H8300"
  "@
  mov.b #0,%x0\;sub.w   %e0,%e0
  mov.b %R1,%w0\;mov.b  #0,%x0\;sub.w   %e0,%e0"
  [(set_attr "length" "4,8")
   (set_attr "cc" "clobber,clobber")])
This is not a regression (can should be able to see using the old machine descriptions).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|optimization                |target


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (3 preceding siblings ...)
  2003-12-06  7:36 ` [Bug target/13313] " pinskia at gcc dot gnu dot org
@ 2003-12-08 14:29 ` mike at ml-solutions dot co dot uk
  2003-12-09  8:20 ` ebotcazou at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mike at ml-solutions dot co dot uk @ 2003-12-08 14:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mike at ml-solutions dot co dot uk  2003-12-08 14:29 -------
I have now investigated this further and can confirm that it started failing on 
the 13th June 2003 following the change associated with this changelog entry

2003-06-13  Jim Wilson  <wilson@tuliptree.org>
            Eric Botcazou  <ebotcazou@libertysurf.fr>

    PR bootstrap/10983
    * combine.c (make_extraction): Use gen_lowpart_for_combine
    when extracting from a REG and not in the destination of a SET.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/13313] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (4 preceding siblings ...)
  2003-12-08 14:29 ` mike at ml-solutions dot co dot uk
@ 2003-12-09  8:20 ` ebotcazou at gcc dot gnu dot org
  2003-12-09  8:34 ` [Bug target/13313] [3.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2003-12-09  8:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2003-12-09 08:19 -------
The aforementioned patch is simply plain broken.  What happened is that Jim gave
the general idea and I wrote the patch, which is obviously dangerous because I
didn't really look carefully at the code.

I'll fix it.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |ebotcazou at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Target Milestone|---                         |3.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (5 preceding siblings ...)
  2003-12-09  8:20 ` ebotcazou at gcc dot gnu dot org
@ 2003-12-09  8:34 ` pinskia at gcc dot gnu dot org
  2003-12-09  8:43 ` ebotcazou at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-09  8:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-09 08:34 -------
Eric, I think what combiner is doing is fine, I had looked really hard to understand what was going 
on (note on h8300, word mode is QI).
The problem looks more like a target problem:
(insn 19 16 20 0 (set (reg:SI r0 [ tmp ])
        (zero_extend:SI (reg:QI r1 [orig:0+3 ] [0]))) 102 {*zero_extendqisi2_h8300} (insn_list 9 (nil))
    (nil))
Say that register r0:r1 = zero_extend:SI (r1:QI) which is right for this case but the target's machine 
description cannot hanndle this at all for some reason (I think it is because the writter never 
thought this would come up).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (6 preceding siblings ...)
  2003-12-09  8:34 ` [Bug target/13313] [3.4 Regression] " pinskia at gcc dot gnu dot org
@ 2003-12-09  8:43 ` ebotcazou at gcc dot gnu dot org
  2003-12-15 19:34 ` [Bug optimization/13313] " kazu at cs dot umass dot edu
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2003-12-09  8:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2003-12-09 08:43 -------
No, no, H8300 is big-endian so it should be

(insn 19 16 20 0 (set (reg:SI r0 [ tmp ])
        (zero_extend:SI (reg:QI r0))) 102 {*zero_extendqisi2_h8300} (insn_list 9
(nil))

because r0 is the high-part of (r0:r1). And I think word mode is HI, not QI.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug optimization/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (7 preceding siblings ...)
  2003-12-09  8:43 ` ebotcazou at gcc dot gnu dot org
@ 2003-12-15 19:34 ` kazu at cs dot umass dot edu
  2003-12-15 20:02 ` kazu at cs dot umass dot edu
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kazu at cs dot umass dot edu @ 2003-12-15 19:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2003-12-15 19:34 -------
I'll also investigate this.
The last comment from Eric is right.
Here is the testcase suitable for our framework.

extern void abort ();
extern void exit (int);

unsigned long
foo (unsigned long a)
{
  return (a & 0x00ff0000L) >> 16;
}

int
main (void)
{
  if (foo (8) != 0)
    abort ();
  exit (0);
}


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kazu at cs dot umass dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug optimization/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (8 preceding siblings ...)
  2003-12-15 19:34 ` [Bug optimization/13313] " kazu at cs dot umass dot edu
@ 2003-12-15 20:02 ` kazu at cs dot umass dot edu
  2003-12-16  8:05 ` cvs-commit at gcc dot gnu dot org
  2003-12-16  8:12 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: kazu at cs dot umass dot edu @ 2003-12-15 20:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2003-12-15 20:02 -------
Oops, I didn't realize a patch has already been posted. :-)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug optimization/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (9 preceding siblings ...)
  2003-12-15 20:02 ` kazu at cs dot umass dot edu
@ 2003-12-16  8:05 ` cvs-commit at gcc dot gnu dot org
  2003-12-16  8:12 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-12-16  8:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-12-16 07:50 -------
Subject: Bug 13313

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-12-16 07:50:32

Modified files:
	gcc            : ChangeLog combine.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20031216-1.c 

Log message:
	PR optimization/13313
	* combine.c (make_extraction) [REG]: Do not use
	gen_lowpart_for_combine when POS is non-zero.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2004&r2=2.2005
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&r1=1.397&r2=1.398
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3263&r2=1.3264
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20031216-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug optimization/13313] [3.4 Regression] Wrong code generated
  2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
                   ` (10 preceding siblings ...)
  2003-12-16  8:05 ` cvs-commit at gcc dot gnu dot org
@ 2003-12-16  8:12 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2003-12-16  8:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2003-12-16 07:57 -------
See http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00981.html


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13313


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2003-12-16  7:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-05 12:10 [Bug c/13313] New: Wrong code generated mike at ml-solutions dot co dot uk
2003-12-05 12:42 ` [Bug c/13313] " bangerth at dealii dot org
2003-12-05 13:15 ` mike at ml-solutions dot co dot uk
2003-12-06  4:35 ` [Bug optimization/13313] " pinskia at gcc dot gnu dot org
2003-12-06  7:36 ` [Bug target/13313] " pinskia at gcc dot gnu dot org
2003-12-08 14:29 ` mike at ml-solutions dot co dot uk
2003-12-09  8:20 ` ebotcazou at gcc dot gnu dot org
2003-12-09  8:34 ` [Bug target/13313] [3.4 Regression] " pinskia at gcc dot gnu dot org
2003-12-09  8:43 ` ebotcazou at gcc dot gnu dot org
2003-12-15 19:34 ` [Bug optimization/13313] " kazu at cs dot umass dot edu
2003-12-15 20:02 ` kazu at cs dot umass dot edu
2003-12-16  8:05 ` cvs-commit at gcc dot gnu dot org
2003-12-16  8:12 ` ebotcazou at gcc dot gnu dot org

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).