Skip to content

Commit 38f8cf7

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent f484ddd commit 38f8cf7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/optimizer.go

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ func (c *Compiler) doesEscape(value llvm.Value) bool {
281281
if !c.hasFlag(use, value, "nocapture") {
282282
return true
283283
}
284+
} else if use.IsAICmpInst() != nilValue {
285+
// Comparing pointers don't let the pointer escape.
286+
// This is often a compiler-inserted nil check.
284287
} else {
285288
// Unknown instruction, might escape.
286289
return true

0 commit comments

Comments
 (0)