CodeWarrior for ColdFire 7.1 Compiler Bug ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CodeWarrior for ColdFire 7.1 Compiler Bug ?

2,355 Views
laurent_mode
Contributor I
Using CodeWarrior 7.0, compiling the following C code :

int a = -10003
a = -10002 - a

will produce the following assembly code

;
;    int a = -10003
;
0x0000003C  0x717CD8ED               mvs.w    #-10003,d0
0x00000040  0x2D40FFB0               move.l   d0,-80(a6)
;
;     a = -10002 - a;
;
0x00000044  0x717CD8EE               mvs.w    #-10002,d0
0x00000048  0x90AEFFB0               sub.l    -80(a6),d0
0x0000004C  0x2D40FFB0               move.l   d0,-80(a6)

that correctly computes the result and stores 1 back in a.

Whereas CodeWarrior 7.1.1  happily compiles that down to
;
;    int a = -10003
;
0x0000003C  0x717CD8ED               mvs.w    #-10003,d0
0x00000040  0x2D40FFB0               move.l   d0,-80(a6)
;
;     a = -10002 - a;
;
0x00000044  0x737CD8EE               mvs.w    #-10002,d1
0x00000048  0x93AEFFB0               sub.l    d1,-80(a6)

which is obviously wrong as it swaps the order of the subtract operands, storing back -1 (!!!!!) in a

As anyone noticed that bug before ? Any idea how such a basic bug could end up in 7.1.1 ?

Regards,
L.


Message Edited by laurent@mode on 2008-09-10 04:25 PM

Message Edited by laurent@mode on 2008-09-10 04:26 PM
Labels (1)
0 Kudos
4 Replies

313 Views
RichTestardi
Senior Contributor II
Can you tell us your compiler optimization level, and whether register coloring, instruction scheduling, and/or peephole optimizations are enabled?  I seem to only reproduce this with level 0 optimizations (which I ordinarily do not use) and the peephole optimizer enabled, though my assembly is different than yours.  Hopefully that might be an easy workaround for you.
 
Level 1 and peephole (OK):
 
int a = -10003;
a = -10002 - a;
000020FA: 203CFFFFD8EE    move.l   #-10002,d0
00002100: 0480FFFFD8ED    subi.l   #-10003,d0
00002106: 2D40FFFC        move.l   d0,-4(a6)
 
Level 0 and no peephole (OK):
 
int a = -10003;
000025AA: 203CFFFFD8ED    move.l   #-10003,d0
000025B0: 2D40FFFC        move.l   d0,-4(a6)
a = -10002 - a;
000025B4: 203CFFFFD8EE    move.l   #-10002,d0
000025BA: 90AEFFFC        sub.l    -4(a6),d0
000025BE: 2D40FFFC        move.l   d0,-4(a6)
 
Level 0 and peephole (BUG):
 
int a = -10003;
000022EE: 203CFFFFD8ED    move.l   #-10003,d0
000022F4: 2D40FFFC        move.l   d0,-4(a6)
a = -10002 - a;
000022F8: 223CFFFFD8EE    move.l   #-10002,d1
000022FE: 93AEFFFC        sub.l    d1,-4(a6)
0 Kudos

313 Views
laurent_mode
Contributor I
Hi Rich,

My compiler is set with no optimisation (level 0), no register coloring but peephole & Instruction scehduling are enabled. I was sticking to level 0 optimisation because CodeWarrior 7.0 could not compile some of my C++ template code with any optimisation turned on.

I will turn peephole off for now.

Thanks for the hint.

L.
0 Kudos

313 Views
J2MEJediMaster
Specialist I
We definitely need to be made aware of this problem. File a service request, including your project and a sample of code that duplicates the error.

---Tom


Message Edited by J2MEJediMaster on 2008-09-11 10:53 AM
0 Kudos

313 Views
RichTestardi
Senior Contributor II
I submitted an SR with the attached sample project.  It also seems register coloring must be disabled for the bug to occur.
0 Kudos