Skip to content

NCG: dead code stripping prevention wastes space

Symptom

Consider this NCG-generated code:

	.long  _T5001a_zdp1Comorphism_info - _T5001a_zdp1Comorphism_info_dsp
.data
.align 3
.align 0
.globl _T5001a_mapzusentence_closure
_T5001a_mapzusentence_closure:
	.quad	_T5001a_mapzusentence_info
.text
.align 3
_T5001a_mapzusentence_info_dsp:
.align 3
	.quad	4294967301
	.quad	0
	.quad	14
.globl _T5001a_mapzusentence_info
_T5001a_mapzusentence_info:

There is an inert .long at the end of each Cmm procedure. This fills up precious instruction cache and wastes space.

Potential solutions

Some ideas to improve the situation follow:

  1. Move all those longs to a "table" at the end of the compilation unit (idea by Henning Thielemann),
  2. coalesce the relocation into the previous instruction by explicitly calculating the opcode (craziness by me),
  3. coalesce the relocation into the following info table like this:
    	.quad	4294967301 - 24 + _T5001a_zdp1Comorphism_info - _T5001a_zdp1Comorphism_info_dsp
  1. Instead of exporting _T5001a_mapzusentence_info export _T5001a_mapzusentence_info_dsp and jump/call _T5001a_mapzusentence_info_dsp + 24 instead. (Idea by Henning Thielemann.)

Discussion

  1. Improves instruction cache only
  2. hard to implement, leads to ugly assembly
  3. wastes a long per compilation unit (at the end), needs a new state in the assembly writer
  4. leads to unintuitive (ugly?) assembly.
Trac metadata
Trac field Value
Version 8.2.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information