From 38f8cf7bee79c4e94ff225f0101e4e547a50e16e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 24 Mar 2019 16:47:36 +0100 Subject: [PATCH] compiler: imporove escape analysis to allow icmp The icmp instruction is often used in nil checks, so this instruction happens very frequently now that TinyGo automatically inserts nil checks everywhere. Escape analysis would conservatively mark such pointers as escaping, which they obviously don't. This commit improves escape analysis to allow icmp instructions. --- compiler/optimizer.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/optimizer.go b/compiler/optimizer.go index d9ab6450..57d2593c 100644 --- a/compiler/optimizer.go +++ b/compiler/optimizer.go @@ -281,6 +281,9 @@ func (c *Compiler) doesEscape(value llvm.Value) bool { if !c.hasFlag(use, value, "nocapture") { return true } + } else if use.IsAICmpInst() != nilValue { + // Comparing pointers don't let the pointer escape. + // This is often a compiler-inserted nil check. } else { // Unknown instruction, might escape. return true