ssa: add support for min and max built-in functions

This commit is contained in:
Aofei Sheng
2024-07-30 17:09:41 +08:00
parent 519b14d506
commit 0a884df74f
2 changed files with 58 additions and 3 deletions

View File

@@ -521,3 +521,34 @@ func TestBasicType(t *testing.T) {
}
}
}
func TestCompareSelect(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("bar", "foo/bar")
params := types.NewTuple(
types.NewVar(0, nil, "a", types.Typ[types.Int]),
types.NewVar(0, nil, "b", types.Typ[types.Int]),
types.NewVar(0, nil, "c", types.Typ[types.Int]),
)
rets := types.NewTuple(types.NewVar(0, nil, "", types.Typ[types.Int]))
sig := types.NewSignatureType(nil, nil, nil, params, rets, false)
fn := pkg.NewFunc("fn", sig, InGo)
b := fn.MakeBody(1)
result := b.compareSelect(token.GTR, fn.Param(0), fn.Param(1), fn.Param(2))
b.Return(result)
assertPkg(t, pkg, `; ModuleID = 'foo/bar'
source_filename = "foo/bar"
define i64 @fn(i64 %0, i64 %1, i64 %2) {
_llgo_0:
%3 = icmp sgt i64 %0, %1
%4 = select i1 %3, i64 %0, i64 %1
%5 = icmp sgt i64 %4, %2
%6 = select i1 %5, i64 %4, i64 %2
ret i64 %6
}
`)
}