This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [rfc] multi-word subreg lowering pass
- From: Paul Schlie <schlie at comcast dot net>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Björn Haase <bjoern dot m dot haase at web dot de>,<gcc-patches at gcc dot gnu dot org>
- Date: Sun, 08 May 2005 03:48:19 -0400
- Subject: Re: [rfc] multi-word subreg lowering pass
10.0.1.2] (c-24-61-199-96.hsd1.nh.comcast.net[24.61.199.96])
by comcast.net (rwcrmhc14) with SMTP
id <20050508074821014009f3b1e>; Sun, 8 May 2005 07:48:21 +0000
User-Agent: Microsoft-Entourage/11.1.0.040913
Date: Sun, 08 May 2005 03:48:19 -0400
Subject: Re: [rfc] multi-word subreg lowering pass
From: Paul Schlie <schlie@comcast.net>
To: Richard Henderson <rth@redhat.com>
CC: Bj=?ISO-8859-1?B?9g==?=rn Haase <bjoern.m.haase@web.de>,
<gcc-patches@gcc.gnu.org>
Message-ID: <BEA33C83.A155%schlie@comcast.net>
In-Reply-To: <20050507224214.GA4245@redhat.com>
Mime-version: 1.0
Content-type: text/plain;
charset="US-ASCII"
Content-transfer-encoding: 7bit
> From: Richard Henderson <rth@redhat.com>
> ...
> The Object is to present the register allocator with something that
> it has more freedom to work with. This doesn't achieve that goal.
Thanks, after building HEAD with your patches applied, I think I better
understand. However there seem to be a few odd things going on. Which the
following code attempts to show: (including signed char casts for lowered
operands even though compiled with unsigned chars, and oddly better code for
in-lined calls than for identical expressions, and finally if the below
function zed is defined first, the compile will terminate with a bus error):
-- main.c: --
volatile char v;
void foo (void) /* for some reason this gets oddly in-lined */
{
char x[5] = {"abcde"};
v = x[v];
}
void bar (void) /* but this doesn't ? */
{
char y[5] = {'a','b','c','d','e'};
v = y[v];
}
char zed (long l) /* this generates a bus error occures if placed first */
{
return v & l;
}
int main ( void )
{
volatile long vl;
long l = vl;
char x[5] = "abcde"; /* references to literal string not marked READONLY
*/
char y[5] = {'a','b','c','d','e'}; // but are if to a literal char array
*/
v = x[v];
v = y[v];
foo();
bar();
v = zed (l); /* this inline call generates unnessisary: eor r25, r25 */
v = v & l; /* this identical expression doesn't ?? */
l = zed (l); /* this inline call generates good code, seting final 0's */
l = l + l; /* just here to break up previous assignment */
l = v & l; /* this idetnical expression unnessisary gens & and's 0's */
l = l + l; /* just here to break up previous assignment */
return l + l;
}
-- main.c.blocks --
;; Function foo (foo)
foo ()
{
char x[5];
char D.1217;
volatile char v.0;
<bb 0>:
x = "abcde";
v.0 = v;
D.1217 = x[(int) v.0];
v = D.1217;
return;
}
;; Function bar (bar)
bar ()
{
char y[5];
char D.1225;
volatile char v.2;
static char C.1[5] = {97, 98, 99, 100, 101};
<bb 0>:
y = C.1;
v.2 = v;
D.1225 = y[(int) v.2];
v = D.1225;
return;
}
;; Function zed (zed)
zed (l)
{
volatile char v.3;
<bb 0>:
v.3 = v;
return (int) (char) ((signed char) v.3 & (signed char) l);
}
;; Function main (main)
main ()
{
long int l.13;
long int l.12;
long int l.11;
volatile char v.3;
signed char D.1315;
volatile char v.3;
char x[5];
char D.1308;
volatile char v.0;
char y[5];
char x[5];
long int l;
volatile long int vl;
int D.1259;
volatile char v.10;
volatile char D.1254;
volatile char v.8;
char D.1249;
char D.1248;
volatile char v.7;
char D.1245;
volatile char v.6;
static char C.5[5] = {97, 98, 99, 100, 101};
<bb 0>:
l = vl;
x = "abcde";
y = C.5;
v.6 = v;
D.1245 = x[(int) v.6];
v = D.1245;
v.7 = v;
D.1248 = y[(int) v.7];
v = D.1248;
x = "abcde";
v.0 = v;
D.1308 = x[(int) v.0];
v = D.1308;
bar ();
v.3 = v;
D.1315 = (signed char) l;
D.1249 = (char) (int) (char) ((signed char) v.3 & D.1315);
v = D.1249;
v.8 = v;
D.1254 = (volatile char) ((signed char) v.8 & D.1315);
v = D.1254;
v.3 = v;
l.11 = (long int) (char) (int) (char) ((signed char) v.3 & D.1315);
l.12 = l.11 + l.11;
v.10 = v;
l.13 = (long int) v.10 & l.12;
D.1259 = (int) (l.13 + l.13);
return D.1259 + D.1259;
}
main.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000010 00800100 00000228 000002bc 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 00000228 00000000 00000000 00000094 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .bss 00000001 00800110 00800110 000002cc 2**0
ALLOC
3 .noinit 00000000 00800111 00800111 000002cc 2**0
CONTENTS
4 .eeprom 00000000 00810000 00810000 000002cc 2**0
CONTENTS
5 .stab 0000063c 00000000 00000000 000002cc 2**2
CONTENTS, READONLY, DEBUGGING
6 .stabstr 00000388 00000000 00000000 00000908 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 46 00 jmp 0x8c <__ctors_end>
4: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
8: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
10: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
14: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
18: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
1c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
20: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
24: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
28: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
2c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
30: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
34: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
38: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
3c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
40: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
44: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
48: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
4c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
50: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
54: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
58: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
5c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
60: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
64: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
68: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
6c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
70: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
74: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
78: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
7c: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
80: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
84: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
88: 0c 94 61 00 jmp 0xc2 <__bad_interrupt>
0000008c <__ctors_end>:
8c: 11 24 eor r1, r1
8e: 1f be out 0x3f, r1 ; 63
90: cf ef ldi r28, 0xFF ; 255
92: d0 e1 ldi r29, 0x10 ; 16
94: de bf out 0x3e, r29 ; 62
96: cd bf out 0x3d, r28 ; 61
00000098 <__do_copy_data>:
98: 11 e0 ldi r17, 0x01 ; 1
9a: a0 e0 ldi r26, 0x00 ; 0
9c: b1 e0 ldi r27, 0x01 ; 1
9e: e8 e2 ldi r30, 0x28 ; 40
a0: f2 e0 ldi r31, 0x02 ; 2
a2: 02 c0 rjmp .+4 ; 0xa8 <.do_copy_data_start>
000000a4 <.do_copy_data_loop>:
a4: 05 90 lpm r0, Z+
a6: 0d 92 st X+, r0
000000a8 <.do_copy_data_start>:
a8: a0 31 cpi r26, 0x10 ; 16
aa: b1 07 cpc r27, r17
ac: d9 f7 brne .-10 ; 0xa4 <.do_copy_data_loop>
000000ae <__do_clear_bss>:
ae: 11 e0 ldi r17, 0x01 ; 1
b0: a0 e1 ldi r26, 0x10 ; 16
b2: b1 e0 ldi r27, 0x01 ; 1
b4: 01 c0 rjmp .+2 ; 0xb8 <.do_clear_bss_start>
000000b6 <.do_clear_bss_loop>:
b6: 1d 92 st X+, r1
000000b8 <.do_clear_bss_start>:
b8: a1 31 cpi r26, 0x11 ; 17
ba: b1 07 cpc r27, r17
bc: e1 f7 brne .-8 ; 0xb6 <.do_clear_bss_loop>
be: 0c 94 b0 00 jmp 0x160 <main>
000000c2 <__bad_interrupt>:
c2: 0c 94 00 00 jmp 0x0 <__heap_end>
000000c6 <foo>:
volatile char v;
void foo (void) /* for some reason this gets oddly in-lined */
{
c6: cf 93 push r28
c8: df 93 push r29
ca: cd b7 in r28, 0x3d ; 61
cc: de b7 in r29, 0x3e ; 62
ce: 25 97 sbiw r28, 0x05 ; 5
d0: 0f b6 in r0, 0x3f ; 63
d2: f8 94 cli
d4: de bf out 0x3e, r29 ; 62
d6: 0f be out 0x3f, r0 ; 63
d8: cd bf out 0x3d, r28 ; 61
char x[5] = {"abcde"};
da: de 01 movw r26, r28
dc: 11 96 adiw r26, 0x01 ; 1
de: e0 e0 ldi r30, 0x00 ; 0
e0: f1 e0 ldi r31, 0x01 ; 1
e2: 85 e0 ldi r24, 0x05 ; 5
e4: 01 90 ld r0, Z+
e6: 0d 92 st X+, r0
e8: 81 50 subi r24, 0x01 ; 1
ea: e1 f7 brne .-8 ; 0xe4 <foo+0x1e>
v = x[v];
ec: 80 91 10 01 lds r24, 0x0110
f0: fe 01 movw r30, r28
f2: e8 0f add r30, r24
f4: f1 1d adc r31, r1
f6: 81 81 ldd r24, Z+1 ; 0x01
f8: 80 93 10 01 sts 0x0110, r24
fc: 25 96 adiw r28, 0x05 ; 5
fe: 0f b6 in r0, 0x3f ; 63
100: f8 94 cli
102: de bf out 0x3e, r29 ; 62
104: 0f be out 0x3f, r0 ; 63
106: cd bf out 0x3d, r28 ; 61
108: df 91 pop r29
10a: cf 91 pop r28
10c: 08 95 ret
0000010e <bar>:
}
void bar (void) /* but this doesn't ? */
{
10e: cf 93 push r28
110: df 93 push r29
112: cd b7 in r28, 0x3d ; 61
114: de b7 in r29, 0x3e ; 62
116: 25 97 sbiw r28, 0x05 ; 5
118: 0f b6 in r0, 0x3f ; 63
11a: f8 94 cli
11c: de bf out 0x3e, r29 ; 62
11e: 0f be out 0x3f, r0 ; 63
120: cd bf out 0x3d, r28 ; 61
char y[5] = {'a','b','c','d','e'};
122: de 01 movw r26, r28
124: 11 96 adiw r26, 0x01 ; 1
126: e6 e0 ldi r30, 0x06 ; 6
128: f1 e0 ldi r31, 0x01 ; 1
12a: 85 e0 ldi r24, 0x05 ; 5
12c: 04 90 lpm r0, Z
12e: 0d 92 st X+, r0
130: 81 50 subi r24, 0x01 ; 1
132: e1 f7 brne .-8 ; 0x12c <bar+0x1e>
v = y[v];
134: 80 91 10 01 lds r24, 0x0110
138: fe 01 movw r30, r28
13a: e8 0f add r30, r24
13c: f1 1d adc r31, r1
13e: 81 81 ldd r24, Z+1 ; 0x01
140: 80 93 10 01 sts 0x0110, r24
144: 25 96 adiw r28, 0x05 ; 5
146: 0f b6 in r0, 0x3f ; 63
148: f8 94 cli
14a: de bf out 0x3e, r29 ; 62
14c: 0f be out 0x3f, r0 ; 63
14e: cd bf out 0x3d, r28 ; 61
150: df 91 pop r29
152: cf 91 pop r28
154: 08 95 ret
00000156 <zed>:
}
char zed (long l) /* this generates a bus error occures if placed first */
{
return v & l;
156: 80 91 10 01 lds r24, 0x0110
15a: 86 23 and r24, r22
}
15c: 99 27 eor r25, r25
15e: 08 95 ret
00000160 <main>:
int main ( void )
{
160: cc ee ldi r28, 0xEC ; 236
162: d0 e1 ldi r29, 0x10 ; 16
164: de bf out 0x3e, r29 ; 62
166: cd bf out 0x3d, r28 ; 61
volatile long vl;
long l = vl;
168: e9 80 ldd r14, Y+1 ; 0x01
16a: fa 80 ldd r15, Y+2 ; 0x02
16c: 0b 81 ldd r16, Y+3 ; 0x03
16e: 1c 81 ldd r17, Y+4 ; 0x04
char x[5] = "abcde"; /* references to literal string not marked READONLY
*/
170: de 01 movw r26, r28
172: 15 96 adiw r26, 0x05 ; 5
174: e0 e0 ldi r30, 0x00 ; 0
176: f1 e0 ldi r31, 0x01 ; 1
178: 85 e0 ldi r24, 0x05 ; 5
17a: 01 90 ld r0, Z+
17c: 0d 92 st X+, r0
17e: 81 50 subi r24, 0x01 ; 1
180: e1 f7 brne .-8 ; 0x17a <main+0x1a>
char y[5] = {'a','b','c','d','e'}; // but are if to a literal char array
*/
182: de 01 movw r26, r28
184: 1a 96 adiw r26, 0x0a ; 10
186: eb e0 ldi r30, 0x0B ; 11
188: f1 e0 ldi r31, 0x01 ; 1
18a: 85 e0 ldi r24, 0x05 ; 5
18c: 04 90 lpm r0, Z
18e: 0d 92 st X+, r0
190: 81 50 subi r24, 0x01 ; 1
192: e1 f7 brne .-8 ; 0x18c <main+0x2c>
v = x[v];
194: 80 91 10 01 lds r24, 0x0110
198: fe 01 movw r30, r28
19a: e8 0f add r30, r24
19c: f1 1d adc r31, r1
19e: 85 81 ldd r24, Z+5 ; 0x05
1a0: 80 93 10 01 sts 0x0110, r24
v = y[v];
1a4: 80 91 10 01 lds r24, 0x0110
1a8: fe 01 movw r30, r28
1aa: e8 0f add r30, r24
1ac: f1 1d adc r31, r1
1ae: 82 85 ldd r24, Z+10 ; 0x0a
1b0: 80 93 10 01 sts 0x0110, r24
1b4: de 01 movw r26, r28
1b6: 1f 96 adiw r26, 0x0f ; 15
1b8: e0 e0 ldi r30, 0x00 ; 0
1ba: f1 e0 ldi r31, 0x01 ; 1
1bc: 85 e0 ldi r24, 0x05 ; 5
1be: 01 90 ld r0, Z+
1c0: 0d 92 st X+, r0
1c2: 81 50 subi r24, 0x01 ; 1
1c4: e1 f7 brne .-8 ; 0x1be <main+0x5e>
1c6: 80 91 10 01 lds r24, 0x0110
1ca: fe 01 movw r30, r28
1cc: e8 0f add r30, r24
1ce: f1 1d adc r31, r1
1d0: 87 85 ldd r24, Z+15 ; 0x0f
1d2: 80 93 10 01 sts 0x0110, r24
foo();
bar();
1d6: 0e 94 87 00 call 0x10e <bar>
1da: 80 91 10 01 lds r24, 0x0110
v = zed (l); /* this inline call generates unnessisary: eor r25, r25 */
1de: 8e 21 and r24, r14
1e0: 99 27 eor r25, r25
1e2: 80 93 10 01 sts 0x0110, r24
v = v & l; /* this identical expression doesn't ?? */
1e6: 80 91 10 01 lds r24, 0x0110
1ea: 8e 21 and r24, r14
1ec: 80 93 10 01 sts 0x0110, r24
1f0: 20 91 10 01 lds r18, 0x0110
l = zed (l); /* this inline call generates good code, seting final 0's */
1f4: 2e 21 and r18, r14
1f6: 33 27 eor r19, r19
1f8: 44 27 eor r20, r20
1fa: 55 27 eor r21, r21
l = l + l; /* just here to break up previous assignment */
1fc: 22 0f add r18, r18
1fe: 33 1f adc r19, r19
200: 44 1f adc r20, r20
202: 55 1f adc r21, r21
l = v & l; /* this idetnical expression unnessisary gens & and's 0's */
204: 80 91 10 01 lds r24, 0x0110
208: 99 27 eor r25, r25
20a: aa 27 eor r26, r26
20c: bb 27 eor r27, r27
20e: 82 23 and r24, r18
210: 93 23 and r25, r19
212: a4 23 and r26, r20
214: b5 23 and r27, r21
l = l + l; /* just here to break up previous assignment */
return l + l;
216: 88 0f add r24, r24
218: 99 1f adc r25, r25
21a: aa 1f adc r26, r26
21c: bb 1f adc r27, r27
}
21e: 88 0f add r24, r24
220: 99 1f adc r25, r25
222: 0c 94 13 01 jmp 0x226 <_exit>
00000226 <_exit>:
226: ff cf rjmp .-2 ; 0x226 <_exit>
-- with compile parameters --
Compiling: main.c
avr-gcc -c -mmcu=atmega64 -I. -g -Os -funsigned-char -funsigned-bitfields
-fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst
-fdump-tree-all -da -I/usr/local/avr/include -std=gnu99
-funsafe-math-optimizations -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.o.d main.c
-o main.o
main.c: In function 'foo':
main.c:7: warning: array subscript has type 'char'
main.c: In function 'bar':
main.c:14: warning: array subscript has type 'char'
main.c: In function 'main':
main.c:31: warning: array subscript has type 'char'
main.c:33: warning: array subscript has type 'char'
Linking: main.elf
avr-gcc -mmcu=atmega64 -I. -g -Os -funsigned-char -funsigned-bitfields
-fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o
-fdump-tree-all -da -I/usr/local/avr/include -std=gnu99
-funsafe-math-optimizations -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.elf.d main.o
--output main.elf -Wl,-Map=main.map,--cref -lm
Creating load file for Flash: main.hex
avr-objcopy -O ihex -R .eeprom main.elf main.hex
Creating load file for EEPROM: main.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex main.elf main.eep
Creating Extended Listing: main.lss
avr-objdump -h -S main.elf > main.lss
Creating Symbol Table: main.sym
avr-nm -n main.elf > main.sym