Bug 37408 - [4.3/4.4 regression] Invalid insn scheduling
Summary: [4.3/4.4 regression] Invalid insn scheduling
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.3.3
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-09-07 16:47 UTC by Andreas Schwab
Modified: 2008-09-09 20:27 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc64-*-*
Build:
Known to work: 4.2.1
Known to fail: 4.3.1 4.4.0
Last reconfirmed: 2008-09-09 09:08:23


Attachments
Testcase (51.82 KB, text/plain)
2008-09-07 16:48 UTC, Andreas Schwab
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2008-09-07 16:47:31 UTC
This is broken during sched2 pass.  Compiled with -m64 -O2.

        lwz 10,1492(7)   # nargs,            <--- uninitialized
        std 9,1272(7)    # specpdl.19,
        li 9,16  # iftmp.21,
        std 3,1488(7)    # nargs, nargs
        std 4,1496(7)    # args, args
        cmpwi 7,10,3     #, tmp307,
Comment 1 Andreas Schwab 2008-09-07 16:48:37 UTC
Created attachment 16248 [details]
Testcase
Comment 2 pinskia@gmail.com 2008-09-07 20:10:02 UTC
Subject: Re:   New: [4.3/4.4 regression] Invalid insn scheduling



Sent from my iPhone

On Sep 7, 2008, at 9:47, "schwab at suse dot de" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> This is broken during sched2 pass.  Compiled with -m64 -O2.
>
>        lwz 10,1492(7)   # nargs,            <--- uninitialized
>        std 9,1272(7)    # specpdl.19,
>        li 9,16  # iftmp.21,
>        std 3,1488(7)    # nargs, nargs
>        std 4,1496(7)    # args, args
>        cmpwi 7,10,3     #, tmp307,
>

Just looking at the assembler suggest an aliasing issue. I had a quick  
look at the code but I did see anything would give an alaising issue.  
Though there were some unions.

>
> -- 
>           Summary: [4.3/4.4 regression] Invalid insn scheduling
>           Product: gcc
>           Version: 4.3.1
>            Status: UNCONFIRMED
>          Keywords: wrong-code
>          Severity: normal
>          Priority: P3
>         Component: rtl-optimization
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: schwab at suse dot de
> GCC target triplet: powerpc64-*-*
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37408
>
Comment 3 Andreas Schwab 2008-09-07 20:29:14 UTC
The corresponding code line:

  register const unsigned char **new_argv
    = (const unsigned char **) __builtin_alloca ((((2) > (nargs - 2) ? (2) : (nargs - 2))) * sizeof (char *));
Comment 4 Jakub Jelinek 2008-09-09 08:12:46 UTC
The alias set is the same:
(insn:TI 2204 2201 78 pr37408.i:9124 (set (reg:DI 6 6)
        (zero_extend:DI (mem/c/i:SI (plus:DI (reg:DI 5 5 [6])
                    (const_int 1492 [0x5d4])) [5 nargs+4 S4 A64]))) 14 {*zero_extendsidi2_internal1} (nil))

(insn:TI 68 82 69 pr37408.i:9114 (set (mem/c/i:DI (plus:DI (reg:DI 5 5)
                (const_int 1488 [0x5d0])) [5 nargs+0 S4 A64])
        (reg:DI 3 3 [ nargs+-4 ])) 337 {*movdi_internal64} (expr_list:REG_DEAD (reg:DI 3 3 [ nargs+-4 ])
        (expr_list:REG_EQUIV (mem/c/i:DI (plus:DI (reg/f:DI 67 ap)
                    (const_int 48 [0x30])) [5 nargs+0 S4 A64])
            (nil))))

Perhaps MEM_SIZE in second insn (originally first) being only 32-bit and not 64-bit is the bug.
Comment 5 Jakub Jelinek 2008-09-09 09:08:22 UTC
Indeed, MEM_SIZE is the cause.

--- gcc/function.c.jj	2008-09-08 09:33:51.000000000 +0200
+++ gcc/function.c	2008-09-09 10:59:15.000000000 +0200
@@ -2332,6 +2332,11 @@ assign_parm_find_stack_rtl (tree parm, s
   stack_parm = gen_rtx_MEM (data->promoted_mode, stack_parm);
 
   set_mem_attributes (stack_parm, parm, 1);
+  /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
+     while promoted mode's size is needed.  */
+  if (data->promoted_mode != BLKmode
+      && data->promoted_mode != DECL_MODE (parm))
+    set_mem_size (stack_parm, GEN_INT (GET_MODE_SIZE (data->promoted_mode)));
 
   boundary = data->locate.boundary;
   align = BITS_PER_UNIT;

gives:

@@ -159,13 +159,13 @@ Fcall_process:
 	ld 9,0(9)	 # specpdl,
 	ld 11,0(11)	 # specpdl_ptr,
 	addis 5,31,0x1	 #,,
-	lwz 6,1492(5)	 # nargs,
-	std 9,1272(5)	 # specpdl.19,
-	li 9,16	 # iftmp.21,
 	std 3,1488(5)	 # nargs, nargs
 	std 4,1496(5)	 # args, args
-	cmpwi 7,6,3	 #, tmp309,
+	std 9,1272(5)	 # specpdl.19,
 	std 11,1280(5)	 # specpdl_ptr.17,
+	li 9,16	 # iftmp.21,
+	lwz 6,1492(5)	 # nargs,
+	cmpwi 7,6,3	 #, tmp309,
 	ble 7,.L3	 #
 	addi 9,6,-2	 # tmp310, tmp5,
 	extsw 9,9	 # tmp311, tmp310

Comment 6 Jakub Jelinek 2008-09-09 19:18:51 UTC
Subject: Bug 37408

Author: jakub
Date: Tue Sep  9 19:17:30 2008
New Revision: 140166

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140166
Log:
	PR rtl-optimization/37408
	* function.c (assign_parm_find_stack_rtl): Set correct MEM_SIZE
	if parm is promoted.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/function.c

Comment 7 Jakub Jelinek 2008-09-09 20:26:20 UTC
Subject: Bug 37408

Author: jakub
Date: Tue Sep  9 20:24:58 2008
New Revision: 140172

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140172
Log:
	PR rtl-optimization/37408
	* function.c (assign_parm_find_stack_rtl): Set correct MEM_SIZE
	if parm is promoted.

Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/function.c

Comment 8 Jakub Jelinek 2008-09-09 20:27:44 UTC
Fixed.