Skip to content

Commit c66d979

Browse files
aykevldeadprogram
authored andcommitted
compiler: avoid some stack frames when this is unnecessary
Some instructions do not create new values, they transform existing values in some way (bitcast, getelementptr, etc.). Do not store them in the stack object. This lowers the size of the repulsion demo from 100kB to 98kB (with a baseline of 72kB for the leaking GC). That's a useful reduction in file size.
1 parent fc9188a commit c66d979

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

compiler/gc.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,28 @@ func (c *Compiler) makeGCStackSlots() bool {
187187
}
188188

189189
// Some trivial optimizations.
190-
if ptr.IsAInstruction().IsNil() || !ptr.IsAPHINode().IsNil() {
190+
if ptr.IsAInstruction().IsNil() {
191+
continue
192+
}
193+
switch ptr.InstructionOpcode() {
194+
case llvm.PHI, llvm.GetElementPtr:
195+
// These values do not create new values: the values already
196+
// existed locally in this function so must have been tracked
197+
// already.
191198
continue
199+
case llvm.ExtractValue, llvm.BitCast:
200+
// These instructions do not create new values, but their
201+
// original value may not be tracked. So keep tracking them for
202+
// now.
203+
// With more analysis, it should be possible to optimize a
204+
// significant chunk of these away.
205+
case llvm.Call, llvm.Load, llvm.IntToPtr:
206+
// These create new values so must be stored locally. But
207+
// perhaps some of these can be fused when they actually refer
208+
// to the same value.
209+
default:
210+
// Ambiguous. These instructions are uncommon, but perhaps could
211+
// be optimized if needed.
192212
}
193213

194214
if !ptr.IsAAllocaInst().IsNil() {

0 commit comments

Comments
 (0)