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.
This commit is contained in:
Ayke van Laethem
2020-03-21 23:00:38 +01:00
committed by Ron Evans
parent bbfa601d27
commit f8876ea245
7 changed files with 13 additions and 72 deletions
-18
View File
@@ -98,24 +98,6 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
OptimizeAllocs(mod)
OptimizeStringToBytes(mod)
// Lower runtime.isnil calls to regular nil comparisons.
isnil := mod.NamedFunction("runtime.isnil")
if !isnil.IsNil() {
builder := mod.Context().NewBuilder()
defer builder.Dispose()
for _, use := range getUses(isnil) {
builder.SetInsertPointBefore(use)
ptr := use.Operand(0)
if !ptr.IsABitCastInst().IsNil() {
ptr = ptr.Operand(0)
}
nilptr := llvm.ConstPointerNull(ptr.Type())
icmp := builder.CreateICmp(llvm.IntEQ, ptr, nilptr, "")
use.ReplaceAllUsesWith(icmp)
use.EraseFromParentAsInstruction()
}
}
} else {
// Must be run at any optimization level.
err := LowerInterfaces(mod)