Hi,
gcc-4.1.0 miscompiles on sh4-linux target.
Attached testcase does not trigger this bug on mainline,
and also correctly compiled with gcc-3.4.5.

For attached testcase, source line 514 is incorrectly compiled with
following command line.

g++ -O2 -g -fno-strict-aliasing -fwrapv \
   -fno-implicit-templates -fno-exceptions -fno-rtti -S -o bad.s sql_select4.ii

incorrect result:
        .loc 1 515 0
        mov.l   @(52,r14),r2
        .loc 1 514 0
        add     #12,r1
        .loc 1 515 0
        mov.l   r2,@-r1
        .loc 1 514 0
        mov     #0,r2
        mov.l   r2,@r1          <===== #0 is stored incorrect address
                                        ("add #4,r1" is needed bofore this
line)

Adding -fno-schedule-insns fixes this.
g++ -O2 -g -fno-schedule-insns -fno-strict-aliasing -fwrapv \
   -fno-implicit-templates -fno-exceptions -fno-rtti -S -o good.s
sql_select4.ii

correct result:
        mov     #0,r2
        .....
        fmov.s  fr6,@r1
        fmov.s  fr7,@-r1
        .loc 1 514 0
        add     #12,r1
        mov.l   r2,@r1
        .loc 1 515 0
        mov.l   @(52,r14),r7
        mov.l   r7,@-r1

On mainline, this problem disapeares after following patch.
2005-11-30  Paolo Bonzini  <[EMAIL PROTECTED]>

        * simplify-rtx.c (simplify_plus_minus): Remove final parameter.
        Always produce an output if we can remove NEGs or canonicalize
        (minus (minus ...)) expressions.  Provide a fast path for the
        two-operand case.
        (simplify_gen_binary): Do not call simplify_plus_minus.
        (simplify_binary_operation_1): Reassociate at the end of the
        function.


-- 
           Summary: [4.1 regression] SH: wrong-code generation
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sugioka at itonet dot co dot jp
 GCC build triplet: sh4-unknown-linux
  GCC host triplet: sh4-unknown-linux
GCC target triplet: sh4-unknown-linux


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

Reply via email to