Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/hlsl_codegen.c:
- LIST_FOR_EACH_ENTRY_SAFE(instr, next, &block->instrs, struct hlsl_ir_node, entry)
- {
if (instr->type == HLSL_IR_CALL)
{
struct hlsl_ir_call *call = hlsl_ir_call(instr);
lower_return(ctx, call->decl, &call->decl->body, false);
}
else if (instr->type == HLSL_IR_IF)
{
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
lower_return(ctx, func, &iff->then_instrs, in_loop);
lower_return(ctx, func, &iff->else_instrs, in_loop);
if (func->early_return_var)
I think I would find it more legible if we stipulated that `early_return_var` always exists, so you can skip a few branches in this function, which is already relatively complicated. This would leave in some more dead code, but hopefully there will eventually be a dead if elimination pass that gets rid of it.
That said, nice function! Before reading that I thought it would have been much more of a pain.