forked from AbleOS/holey-bytes
simplifiing upcasts, hwich conincidentally allowed more optimizations
This commit is contained in:
parent
5926f69e6c
commit
e8a8fa3eb1
|
@ -567,11 +567,6 @@ impl Nodes {
|
||||||
return Some(self[self[target].inputs[2]].inputs[1]);
|
return Some(self[self[target].inputs[2]].inputs[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
K::Extend => {
|
|
||||||
if self[target].ty.simple_size() == self[self[target].inputs[1]].ty.simple_size() {
|
|
||||||
return Some(self[target].inputs[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
K::Loop => {
|
K::Loop => {
|
||||||
if self[target].inputs[0] == NEVER {
|
if self[target].inputs[0] == NEVER {
|
||||||
return Some(NEVER);
|
return Some(NEVER);
|
||||||
|
@ -684,7 +679,6 @@ impl Nodes {
|
||||||
Kind::Stre => write!(out, "stre: "),
|
Kind::Stre => write!(out, "stre: "),
|
||||||
Kind::Mem => write!(out, " mem: "),
|
Kind::Mem => write!(out, " mem: "),
|
||||||
Kind::Loops => write!(out, " loops: "),
|
Kind::Loops => write!(out, " loops: "),
|
||||||
Kind::Extend => write!(out, " ext: "),
|
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
if self[node].kind != Kind::Loop && self[node].kind != Kind::Region {
|
if self[node].kind != Kind::Loop && self[node].kind != Kind::Region {
|
||||||
|
@ -1042,8 +1036,6 @@ pub enum Kind {
|
||||||
Phi,
|
Phi,
|
||||||
Arg,
|
Arg,
|
||||||
// [ctrl, oper]
|
// [ctrl, oper]
|
||||||
Extend,
|
|
||||||
// [ctrl, oper]
|
|
||||||
UnOp {
|
UnOp {
|
||||||
op: lexer::TokenKind,
|
op: lexer::TokenKind,
|
||||||
},
|
},
|
||||||
|
@ -2151,22 +2143,11 @@ impl<'a> Codegen<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.tys.size_of(val.ty).cmp(&self.tys.size_of(ty)) {
|
if self.tys.size_of(val.ty) < self.tys.size_of(ty) {
|
||||||
core::cmp::Ordering::Less => {
|
self.extend(&mut val, ty);
|
||||||
self.extend(&mut val, ty);
|
Some(val)
|
||||||
Some(val)
|
} else {
|
||||||
}
|
Some(val.ty(ty))
|
||||||
core::cmp::Ordering::Equal => Some(val.ty(ty)),
|
|
||||||
core::cmp::Ordering::Greater => {
|
|
||||||
let value = (1i64 << (self.tys.size_of(ty) * 8)) - 1;
|
|
||||||
let mask = self.ci.nodes.new_node_nop(val.ty, Kind::CInt { value }, [VOID]);
|
|
||||||
let inps = [VOID, val.id, mask];
|
|
||||||
Some(self.ci.nodes.new_node_lit(
|
|
||||||
ty,
|
|
||||||
Kind::BinOp { op: TokenKind::Band },
|
|
||||||
inps,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::Directive { name: "as", args: [ty, expr], .. } => {
|
Expr::Directive { name: "as", args: [ty, expr], .. } => {
|
||||||
|
@ -3164,7 +3145,9 @@ impl<'a> Codegen<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(oper) = to_correct {
|
if let Some(oper) = to_correct {
|
||||||
self.extend(oper, upcasted);
|
if self.tys.size_of(upcasted) > self.tys.size_of(oper.ty) {
|
||||||
|
self.extend(oper, upcasted);
|
||||||
|
}
|
||||||
if matches!(op, TokenKind::Add | TokenKind::Sub)
|
if matches!(op, TokenKind::Add | TokenKind::Sub)
|
||||||
&& let Some(elem) = self.tys.base_of(upcasted)
|
&& let Some(elem) = self.tys.base_of(upcasted)
|
||||||
{
|
{
|
||||||
|
@ -3224,8 +3207,11 @@ impl<'a> Codegen<'a> {
|
||||||
|
|
||||||
fn extend(&mut self, value: &mut Value, to: ty::Id) {
|
fn extend(&mut self, value: &mut Value, to: ty::Id) {
|
||||||
self.strip_ptr(value);
|
self.strip_ptr(value);
|
||||||
|
let val = (1i64 << (self.tys.size_of(value.ty) * 8)) - 1;
|
||||||
value.ty = to;
|
value.ty = to;
|
||||||
value.id = self.ci.nodes.new_node(to, Kind::Extend, [VOID, value.id]);
|
let mask = self.ci.nodes.new_node_nop(to, Kind::CInt { value: val }, [VOID]);
|
||||||
|
let inps = [VOID, value.id, mask];
|
||||||
|
*value = self.ci.nodes.new_node_lit(to, Kind::BinOp { op: TokenKind::Band }, inps);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
|
|
@ -312,12 +312,6 @@ impl ItemCtx {
|
||||||
4 => instrs::li32(atr(allocs[0]), value as _),
|
4 => instrs::li32(atr(allocs[0]), value as _),
|
||||||
_ => instrs::li64(atr(allocs[0]), value as _),
|
_ => instrs::li64(atr(allocs[0]), value as _),
|
||||||
}),
|
}),
|
||||||
Kind::Extend => {
|
|
||||||
let base = fuc.nodes[node.inputs[1]].ty;
|
|
||||||
let dest = node.ty;
|
|
||||||
|
|
||||||
self.emit(extend(base, dest, 1, 0))
|
|
||||||
}
|
|
||||||
Kind::UnOp { op } => {
|
Kind::UnOp { op } => {
|
||||||
let op = op.unop().expect("TODO: unary operator not supported");
|
let op = op.unop().expect("TODO: unary operator not supported");
|
||||||
let &[dst, oper] = allocs else { unreachable!() };
|
let &[dst, oper] = allocs else { unreachable!() };
|
||||||
|
@ -812,10 +806,6 @@ impl<'a> Function<'a> {
|
||||||
let ops = vec![self.drg(nid)];
|
let ops = vec![self.drg(nid)];
|
||||||
self.add_instr(nid, ops);
|
self.add_instr(nid, ops);
|
||||||
}
|
}
|
||||||
Kind::Extend => {
|
|
||||||
let ops = vec![self.drg(nid), self.urg(node.inputs[1])];
|
|
||||||
self.add_instr(nid, ops);
|
|
||||||
}
|
|
||||||
Kind::Entry => {
|
Kind::Entry => {
|
||||||
self.nodes[nid].ralloc_backref = self.add_block(nid);
|
self.nodes[nid].ralloc_backref = self.add_block(nid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue