ssa: binop fix shl/shr size

This commit is contained in:
visualfc
2024-05-16 10:20:02 +08:00
parent 2b9fb88bf0
commit 6e4ebeddf4
3 changed files with 65 additions and 0 deletions

View File

@@ -328,6 +328,11 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr {
if op == token.SHR && kind == vkUnsigned {
llop = llvm.LShr // Logical Shift Right
}
if op == token.SHL || op == token.SHR {
if b.Prog.SizeOf(x.Type) != b.Prog.SizeOf(y.Type) {
y = b.Convert(x.Type, y)
}
}
return Expr{llvm.CreateBinOp(b.impl, llop, x.impl, y.impl), x.Type}
case isPredOp(op): // op: == != < <= < >=
tret := b.Prog.Bool()