diff options
author | Ayke van Laethem <[email protected]> | 2021-03-18 02:56:03 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-03-23 14:32:33 +0100 |
commit | 19dec048b0746b21559d0bc88653d11ab61b50f0 (patch) | |
tree | 7a1dfd3d3b0470a3bf2c3e6243eefba8a0e45eeb /interp/testdata | |
parent | bbb2909283dd9caca03a14a2c39e5f77b18366a7 (diff) | |
download | tinygo-19dec048b0746b21559d0bc88653d11ab61b50f0.tar.gz tinygo-19dec048b0746b21559d0bc88653d11ab61b50f0.zip |
compiler: do not check for impossible type asserts
Previously there was code to avoid impossible type asserts but it wasn't
great and in fact was too aggressive when combined with reflection.
This commit improves this by checking all types that exist in the
program that may appear in an interface (even struct fields and the
like) but without creating runtime.typecodeID objects with the type
assert. This has two advantages:
* As mentioned, it optimizes impossible type asserts away.
* It allows methods on types that were only asserted on (in
runtime.typeAssert) but never used in an interface to be optimized
away using GlobalDCE. This may have a cascading effect so that other
parts of the code can be further optimized.
This sometimes massively improves code size and mostly negates the code
size regression of the previous commit.
Diffstat (limited to 'interp/testdata')
-rw-r--r-- | interp/testdata/interface.ll | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/interp/testdata/interface.ll b/interp/testdata/interface.ll index 5b7798ba2..8031632f7 100644 --- a/interp/testdata/interface.ll +++ b/interp/testdata/interface.ll @@ -6,10 +6,11 @@ target triple = "x86_64--linux" @main.v1 = global i1 0 @"reflect/types.type:named:main.foo" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i64 0, %runtime.interfaceMethodInfo* null } +@"reflect/types.type:named:main.foo$id" = external constant i8 @"reflect/types.type:basic:int" = external constant %runtime.typecodeID -declare i1 @runtime.typeAssert(i64, %runtime.typecodeID*, i8*, i8*) +declare i1 @runtime.typeAssert(i64, i8*, i8*, i8*) define void @runtime.initAll() unnamed_addr { entry: @@ -20,7 +21,7 @@ entry: define internal void @main.init() unnamed_addr { entry: ; Test type asserts. - %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:main.foo" to i64), %runtime.typecodeID* @"reflect/types.type:named:main.foo", i8* undef, i8* null) + %typecode = call i1 @runtime.typeAssert(i64 ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:main.foo" to i64), i8* @"reflect/types.type:named:main.foo$id", i8* undef, i8* null) store i1 %typecode, i1* @main.v1 ret void } |