http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57836
Bug ID: 57836 Summary: large constants evaluated inline Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: amodra at gmail dot com On powerpc64 with -mcmodel=small -O1, this int x; void f1 (long long hx) { if (hx < 0x3ff0000000000000LL) x++; } results in .L.f1: lis 9,0x3fef ori 9,9,65535 sldi 9,9,32 oris 9,9,0xffff ori 9,9,65535 cmpd 7,3,9 bgtlr 7 ld 9,.LC1@toc(2) lwz 10,0(9) addi 10,10,1 stw 10,0(9) blr The -mcmodel isn't significant, just there to make comparison with older compilers easy. Prior to gcc-4.5 we generated .L.f1: ld 0,.LC0@toc(2) cmpd 7,3,0 bgtlr 7 ld 9,.LC1@toc(2) lwz 11,0(9) addi 0,11,1 stw 0,0(9) blr Both pre- and post-4.5 compilers initially expand rtl using the constant load from toc, but 4.5 and later substitute the constant in the first cse pass. The problem stems from rtx cost for the load from toc being the same as the inline constant form. The costs are the same both pre- and post-4.5. The reason pre-4.5 does not substitute the constant is related to this comment is cse.c: /* Find cheapest and skip it for the next time. For items of equal cost, use this order: src_folded, src, src_eqv, src_related and hash table entry. */ Pre-4.5 src_folded is NULL, src is a mem, src_eqv the constant. Post-4.5 src_folded is the constant, src is a mem, src_eqv the constant again. Pre-4.5, rs6000.c lacked delegitimize_address. src_folded is set by fold_rtx, which calls equiv_constant, which calls avoid_constant_pool_reference, which calls targetm.delegitimize_address. When this is missing, we don't get to see the constant..