Skip to content

consider eliminating final fields with trivial initializers #47120

@mraleph

Description

@mraleph
const y = 0xDEADBEEF;
final int x = 0xFEEDFEED;

void main(List<String> args) {
  print(x);
  print(y);
  print(x + y);
}

results in:

*** BEGIN CFG
After AllocateRegisters
==== file:///usr/local/google/home/vegorov/src/temp/tst/bin/tst.dart_::_main (RegularFunction)
  0: B0[graph]:0 {
      v0 <- Constant(#null) T{Null?}
      v5 <- Constant(#3735928559) [3735928559, 3735928559] T{_Smi}
      v18 <- UnboxedConstant(#3735928559 int64) [3735928559, 3735928559] T{_Smi}
}
  2: B1[function entry]:2 {
      v2 <- Parameter(0) T{List<String>}
}
  4:     CheckStackOverflow:8(stack=0, loop=0)
  6:     v3 <- LoadStaticField(x) T{int?}
  7:     ParallelMove S-1 <- rax
  8:     PushArgument(v3)
 10:     StaticCall:12( print<0> v3)
 12:     PushArgument(v5)
 14:     StaticCall:14( print<0> v5)
 15:     ParallelMove rax <- S-1
 16:     CheckNull:16(v3 T{int?}, NoSuchMethodError) [-9223372036854775808, 9223372036854775807] T{int}
 18:     ParallelMove rax <- rax
 18:     v14 <- UnboxInt64([non-speculative], v3 T{int}) [-9223372036854775808, 9223372036854775807] T{int}
 20:     ParallelMove rcx <- rax
 20:     v8 <- BinaryInt64Op(+ [tr], v14 T{int}, v18) [-9223372036854775808, 9223372036854775807] T{int}
 22:     v16 <- BoxInt64(v8) [-9223372036854775808, 9223372036854775807] T{int}
 23:     ParallelMove rax <- rax
 24:     PushArgument(v16 T{int})
 26:     StaticCall:18( print<0> v16 T{int})
 27:     ParallelMove rax <- C
 28:     Return:22(v0)
*** END CFG

We should probably eliminate the field altogether by inlining all LoadStaticField from it.

/cc @alexmarkov

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-performanceIssue relates to performance or code sizevm-aot-code-sizeRelated to improvements in AOT code size

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions