diff options
author | Ayke van Laethem <[email protected]> | 2020-03-21 23:00:38 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-03-27 07:38:16 +0100 |
commit | f8876ea245bcd73b0a668f9ae12463d3020c07ec (patch) | |
tree | 29112a96651579a87c879ff5d40f23eca44483a6 /compiler/asserts.go | |
parent | bbfa601d27530c0adf38db446b510cd79a017ea2 (diff) | |
download | tinygo-f8876ea245bcd73b0a668f9ae12463d3020c07ec.tar.gz tinygo-f8876ea245bcd73b0a668f9ae12463d3020c07ec.zip |
compiler, transform: remove runtime.isnil hack
This hack was originally introduced in
https://github.com/tinygo-org/tinygo/pull/251 to fix an escape analysis
regression after https://github.com/tinygo-org/tinygo/pull/222
introduced nil checks. Since a new optimization in LLVM (see
https://reviews.llvm.org/D60047) this hack is not necessary anymore and
can be removed.
I've compared all regular tests and smoke tests before and after to
check the size. In most cases this change was an improvement although
there are a few regressions.
Diffstat (limited to 'compiler/asserts.go')
-rw-r--r-- | compiler/asserts.go | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/compiler/asserts.go b/compiler/asserts.go index c72671634..f1ae259ea 100644 --- a/compiler/asserts.go +++ b/compiler/asserts.go @@ -176,23 +176,11 @@ func (b *builder) createNilCheck(inst ssa.Value, ptr llvm.Value, blockPrefix str } // Compare against nil. - var isnil llvm.Value - if ptr.Type().PointerAddressSpace() == 0 { - // Do the nil check using the isnil builtin, which marks the parameter - // as nocapture. - // The reason it has to go through a builtin, is that a regular icmp - // instruction may capture the pointer in LLVM semantics, see - // https://reviews.llvm.org/D60047 for details. Pointer capturing - // unfortunately breaks escape analysis, so we use this trick to let the - // functionattr pass know that this pointer doesn't really escape. - ptr = b.CreateBitCast(ptr, b.i8ptrType, "") - isnil = b.createRuntimeCall("isnil", []llvm.Value{ptr}, "") - } else { - // Do the nil check using a regular icmp. This can happen with function - // pointers on AVR, which don't benefit from escape analysis anyway. - nilptr := llvm.ConstPointerNull(ptr.Type()) - isnil = b.CreateICmp(llvm.IntEQ, ptr, nilptr, "") - } + // We previously used a hack to make sure this wouldn't break escape + // analysis, but this is not necessary anymore since + // https://reviews.llvm.org/D60047 has been merged. + nilptr := llvm.ConstPointerNull(ptr.Type()) + isnil := b.CreateICmp(llvm.IntEQ, ptr, nilptr, "") // Emit the nil check in IR. b.createRuntimeAssert(isnil, blockPrefix, "nilPanic") |