compiler: do not emit nil checks for *ssa.Alloc instructions

An allocated object is never nil, so there is no need for a nil check.
This probably does not result in any better optimization (the nil check
is easily optimized away by LLVM because the result of runtime.alloc is
marked nonnull) but it makes the slice tests a bit cleaner.
This commit is contained in:
Ayke van Laethem
2021-03-08 14:18:04 +01:00
committed by Ron Evans
parent 2709d38d63
commit 0db4b13e37
2 changed files with 3 additions and 26 deletions
+3
View File
@@ -159,6 +159,9 @@ func (b *builder) createNilCheck(inst ssa.Value, ptr llvm.Value, blockPrefix str
}
switch inst := inst.(type) {
case *ssa.Alloc:
// An alloc is never nil.
return
case *ssa.IndexAddr:
// This pointer is the result of an index operation into a slice or
// array. Such slices/arrays are already bounds checked so the pointer