Optimize recast.

This commit is contained in:
Christoffer Lerno
2025-01-04 21:57:58 +01:00
parent 61badb6af7
commit 6f9b466d7c
3 changed files with 44 additions and 16 deletions

View File

@@ -94,12 +94,24 @@ LLVMValueRef llvm_emit_expect_raw(GenContext *c, LLVMValueRef expect_true)
return llvm_emit_call_intrinsic(c, intrinsic_id.expect, &c->bool_type, 1, values, 2);
}
Expr *expr_remove_recast(Expr *expr)
{
Type *main_type = type_lowering(expr->type);
while (expr->expr_kind == EXPR_RECAST && main_type == type_lowering(expr->inner_expr->type))
{
expr = expr->inner_expr;
}
return expr;
}
BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValueRef optional, bool is_init)
{
ASSERT0(llvm_value_is_addr(ref));
assert((optional || !IS_OPTIONAL(expr)) && "Assumed an optional address if it's an optional expression.");
expr = expr_remove_recast(expr);
// Special optimization of handling of optional
if (expr->expr_kind == EXPR_OPTIONAL)
{