compiler: add minsize attribute for -Oz

This matches the behavior of Clang, which uses optsize for -Os and adds
minsize for -Oz.

The code size change is all over the map, but using a hacked together
size comparison tool I've found that there is a slight reduction in
binary size overall (-1.6% with the tinygo smoke tests and -0.8% for the
drivers smoke test).
This commit is contained in:
Ayke van Laethem
2021-11-01 18:37:00 +01:00
committed by Ron Evans
parent d7b7583e83
commit 7c24925aa7
3 changed files with 15 additions and 5 deletions
+4 -1
View File
@@ -22,7 +22,10 @@ import (
// the -opt= compiler flag.
func AddStandardAttributes(fn llvm.Value, config *compileopts.Config) {
_, sizeLevel, _ := config.OptLevels()
if sizeLevel >= 2 {
if sizeLevel >= 1 {
fn.AddFunctionAttr(fn.Type().Context().CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
}
if sizeLevel >= 2 {
fn.AddFunctionAttr(fn.Type().Context().CreateEnumAttribute(llvm.AttributeKindID("minsize"), 0))
}
}