Testcase: unsigned int f(void) { return 0x80000001UL; } This should be able to done in three instructions: .f: li 3,1 oris 3,3,0x8000 blr Right now it is done as: .L.f: li 3,0 ori 3,3,32768 sldi 3,3,16 ori 3,3,1 blr Which is (0x8000 << 16) | 1 but (0x8000 << 16) is what is done for oris.
Confirmed.
Still present in GCC 4.5.0 20090513.
FWIW, 4.8.0 20120809 w/ -O1 or higher is now using just 4 instructions instead of 5. So, "half way there". .L.f: lis 3,0x8000 ori 3,3,1 rldicl 3,3,0,32 blr
(In reply to comment #3) > FWIW, 4.8.0 20120809 w/ -O1 or higher is now using just 4 instructions instead > of 5. So, "half way there". > > > .L.f: > lis 3,0x8000 > ori 3,3,1 > rldicl 3,3,0,32 > blr That was for a 64-bit target, where the need to zero the upper half of r3 (which is 0xffffffff due to sign extension of 0x8000 by 'lis') accounts for the 4th instruction. So, there is still room for improvement using the originally proposed 3-instruction sequence (since 'oris' won't sign-extend as 'lis' does). For a 32-bit target, it appears that GCC 4.8.0 20120809 has reached the desired three instructions: f: lis 3,0x8000 ori 3,3,1 blr
Fixed on trunk, no backports planned, closing.
Actually, huh, *not* fixed on trunk yet.
(In reply to Segher Boessenkool from comment #6) > Actually, huh, *not* fixed on trunk yet. This was fixed in GCC 13. Marking it as FIXED.