This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine][Thumb] Use single CP entry for addressing GV with large offset
AbandonedPublic

Authored by zzheng on Jun 3 2019, 5:08 PM.

Details

Summary
Original patch by Weiming Zhao.

When addressing a global variable with large offsets, the offset may not fit in
the load instruction and thus either needs rematerializaion or extra constant
pool entry. This casues code size bloat, especially on Thumb1.

This patch tries to encode the offset in the CP entry to save code size.

For example:
  &g_big_struct.x_offset_300

Before:                         After:
movs r0, #75                    ldr r1, .LCPI0_0
lsls r0, r0, #2                 .LCPI0_0: .long g_big_struct + 300
ldr  r1, .LCPI0_0
adds r0, r1
.LCPI0_0: .long g_big_struct

In best case, it saves 3 insts (and potentially reduces register pressure) as
the example shows.

In worst case, if the GV has multiple uses, the original CP entry for the GV
base is still needed, and the member can be calculated from previous addressing,
it will cost 4 extra bytes (for the CP entry).

Diff Detail

Repository
rL LLVM