13373 – [3.3 regression] optimization with -frerun-cse-after-loop -fexpensive-optimizations produces wrong code on mcore (original) (raw)

| Description Olaf Bonorden 2003-12-10 10:38:35 UTC Compilation of a crc8 faild: source: unsigned short Calc_crc8(unsigned char data, unsigned short crc ) { unsigned char i,x16,carry; for (i = 0; i < 8; i++) { x16 = (unsigned char)((data & 1) ^ ((unsigned char)crc & 1)); data >>= 1; if (x16 == 1) { crc ^= 0x4002; carry = 1; } else carry = 0; crc >>= 1; if (carry) crc |= 0x8000; else crc &= 0x7fff; } return crc; } ----------- Compilation with "mcore-be-elf-gcc -mbig-endian -O0 -frerun-cse-after-loop crc.c -S" is ok, with "mcore-be-elf-gcc -mbig-endian -O0 -frerun-cse-after-loop -fexpensive-optimizations crc.c -S" the code is not correct. Part in the produced assembler code: first version: ld.h r7,(r8,2) bgeni r6,14 addi r6,2 // 16386 0x4002 xor r7,r6 st.h r7,(r8,2) ldw r6,(r8,8) st.b r6,(r8,6) wrong second version: ld.h r7,(r8,2) st.h r7,(r8,2) ldw r7,(r8,8) st.b r7,(r8,6) The xor part is removed :-( Compiler without optimization is nearly useless. Comment 1 Kazu Hirata 2003-12-24 05:30:47 UTC Confirmed on 3.3. Not the case on mainline. Reduced to: short foo (short crc) { if (crc) crc ^= 0x4002; return crc; } With -O1 instead of -O0, the difference is easier to see: foo: zexth r2 cmpnei r2,0 jbf .L2 - bgeni r7,14 - addi r7,2 // 16386 0x4002 - xor r2,r7 + zexth r2 .L2: sexth r2 jmp r15 Comment 2 Kazu Hirata 2003-12-24 05:49:11 UTC In my reduced case, xor is removed during the first cse pass. Comment 3 Kazu Hirata 2003-12-24 05:52:32 UTC Reduced to: short foo (short crc) { return crc ^ 0x4002; } The problem still seems to be cse. Comment 5 Kazu Hirata 2003-12-24 21:20:13 UTC OK with 3.2 branch, so this is a regression from 3.2.x. Comment 8 Kazu Hirata 2004-01-01 00:28:23 UTC Just backported a fix. | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |