Overview Description: gcc 3.3 or gcc 4.0 on Apple's OSX 10.4 generates bad code that references r31 when called with -O1 -fno-pic. If you use -O0 or do not use -fno-pic the problem. Steps to Reproduce: run gcc -O1 -fno-pic -c or gcc-4.0 -O1 -fno-pic -c on: void broken(double *ret, int num) { ret[0] = num ? 0.1 : 0.0; } Actual Results: Compile this source file with "gcc-4.0 -c -O1 -fno-pic". View the object file with "otool -lrtvdI -s __TEXT __literal8": [...] Relocation information (__TEXT,__text) 8 entries address pcrel length extern type scattered symbolnum/value 00000014 False long n/a LO16 True 0x00000030 False long False PAIR False half = 0x0000 00000010 False long n/a HA16 True 0x00000030 False long False PAIR False half = 0x0034 0000000c False long False LO16 False 2 (__TEXT,__literal8) False long False PAIR False half = 0x0000 00000008 False long False HA16 False 2 (__TEXT,__literal8) False long False PAIR False half = 0x0030 (__TEXT,__text) section _broken: 00000000 cmpwi cr7,r4,0x0 00000004 beq+ cr7,0x1c 00000008 lis r2,0x0 0000000c lwz r9,0x30(r2) 00000010 addis r10,r31,0x0 00000014 lwz r10,0x34(r10) 00000018 b 0x24 0000001c li r9,0x0 00000020 li r10,0x0 00000024 stw r9,0x0(r3) 00000028 stw r10,0x4(r3) 0000002c blr Contents of (__TEXT,__literal8) section 00000030 0x3fb99999 0x9999999a (1.0000000000000001e-01) Observe that "r31" is being used without being initialized. Expected Results: It should not reference r31 unless it has initialized it... And if you compile this source file with "gcc-4.0 -c -O1". View the object file with "otool -lrtvdI -s __TEXT __literal8": [...] Relocation information (__TEXT,__text) 8 entries address pcrel length extern type scattered symbolnum/value 00000024 False long n/a LO16DIF True 0x00000040 False long n/a PAIR True 0x00000008 other_half = 0x0000 00000020 False long n/a HA16DIF True 0x00000040 False long n/a PAIR True 0x00000008 other_half = 0x003c 0000001c False long n/a LO16DIF True 0x00000040 False long n/a PAIR True 0x00000008 other_half = 0x0000 00000018 False long n/a HA16DIF True 0x00000040 False long n/a PAIR True 0x00000008 other_half = 0x0038 (__TEXT,__text) section _broken: 00000000 mfspr r0,lr 00000004 bcl 20,31,0x8 00000008 mfspr r8,lr 0000000c mtspr lr,r0 00000010 cmpwi cr7,r4,0x0 00000014 beq+ cr7,0x2c 00000018 addis r2,r8,0x0 0000001c lwz r9,0x38(r2) 00000020 addis r10,r8,0x0 00000024 lwz r10,0x3c(r10) 00000028 b 0x34 0000002c li r9,0x0 00000030 li r10,0x0 00000034 stw r9,0x0(r3) 00000038 stw r10,0x4(r3) 0000003c blr Contents of (__TEXT,__literal8) section 00000040 0x3fb99999 0x9999999a (1.0000000000000001e-01) Observe that the code seems reasonable.
with powerpc-unknown-linux and 4.1.0 I get (-O1 -fno-pic -mbss-plt) broken: cmpwi 7,4,0 beq 7,.L2 lis 9,.LC0@ha lfd 0,.LC0@l(9) b .L4 .L2: lis 9,.LC1@ha lfd 0,.LC1@l(9) .L4: stfd 0,0(3) blr
This comes from the following pattern: (define_insn "movdf_low_si" [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r") (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b") (match_operand 2 "" ""))))] "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && !TARGET_64BIT" But this has been fixed in 4.1.0 by: 2005-10-08 Andrew Pinski <pinskia@physics.uc.edu> PR target/24136 * config/rs6000/darwin.md (movdf_low_si): Remove early clobber. Rewrite for no need for the early clobber. 2005-09-13 Andrew Pinski <pinskia@physics.uc.edu> * config/rs6000/darwin.md (movdf_low_si): Mark the outgoing r constraint as early clobber. Rewrite so the PIC register is not implicitly used. I rewrote this part so that there was no need for the PIC register.