From 6e8eeb8f7ad0d9226a1a2e9f6bac7bdd084c9856 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Wed, 20 Aug 2025 17:47:47 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Use replace_ir() for hlsl_fold_constant_identities(). --- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl_codegen.c | 2 +- libs/vkd3d-shader/hlsl_constant_ops.c | 37 ++++++++++----------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c1897defe..a24493e51 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1836,7 +1836,8 @@ struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_dere bool hlsl_copy_propagation_execute(struct hlsl_ctx *ctx, struct hlsl_block *block); bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); -bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); +struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx, + struct hlsl_ir_node *instr, struct hlsl_block *block); bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); struct hlsl_ir_node *hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 2497f2065..57127403e 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -8474,7 +8474,7 @@ static bool simplify_exprs(struct hlsl_ctx *ctx, struct hlsl_block *block) progress |= hlsl_transform_ir(ctx, hlsl_normalize_binary_exprs, block, NULL); progress |= hlsl_transform_ir(ctx, fold_unary_identities, block, NULL); progress |= hlsl_transform_ir(ctx, fold_conditional_identities, block, NULL); - progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_identities, block, NULL); + progress |= replace_ir(ctx, hlsl_fold_constant_identities, block); progress |= replace_ir(ctx, hlsl_fold_constant_swizzles, block); any_progress |= progress; diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index e0e9d307e..23da294fc 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -1647,27 +1647,27 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, return success; } -bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx, + struct hlsl_ir_node *instr, struct hlsl_block *block) { static const struct hlsl_constant_value zero; struct hlsl_ir_constant *const_arg = NULL; struct hlsl_ir_node *mut_arg = NULL; - struct hlsl_ir_node *res_node; struct hlsl_ir_expr *expr; unsigned int i; if (instr->type != HLSL_IR_EXPR) - return false; + return NULL; expr = hlsl_ir_expr(instr); if (instr->data_type->class > HLSL_CLASS_VECTOR) - return false; + return NULL; /* Verify that the expression has two operands. */ for (i = 0; i < ARRAY_SIZE(expr->operands); ++i) { if (!!expr->operands[i].node != (i < 2)) - return false; + return NULL; } if (expr->operands[0].node->type == HLSL_IR_CONSTANT) @@ -1682,34 +1682,33 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in } else { - return false; + return NULL; } - res_node = NULL; switch (expr->op) { case HLSL_OP2_ADD: if (hlsl_constant_is_zero(const_arg)) - res_node = mut_arg; + return mut_arg; break; case HLSL_OP2_MUL: if (hlsl_constant_is_one(const_arg)) - res_node = mut_arg; + return mut_arg; break; case HLSL_OP2_LOGIC_AND: if (hlsl_constant_is_zero(const_arg)) - res_node = &const_arg->node; + return &const_arg->node; else if (hlsl_constant_is_one(const_arg)) - res_node = mut_arg; + return mut_arg; break; case HLSL_OP2_LOGIC_OR: if (hlsl_constant_is_zero(const_arg)) - res_node = mut_arg; + return mut_arg; else if (hlsl_constant_is_one(const_arg)) - res_node = &const_arg->node; + return &const_arg->node; break; case HLSL_OP2_LESS: @@ -1718,21 +1717,13 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in || expr->operands[1].node->type != HLSL_IR_CONSTANT || !hlsl_constant_is_zero(hlsl_ir_constant(expr->operands[1].node))) break; - if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &zero, &instr->loc))) - break; - list_add_before(&expr->node.entry, &res_node->entry); - break; + return hlsl_block_add_constant(ctx, block, instr->data_type, &zero, &instr->loc); default: break; } - if (res_node) - { - hlsl_replace_node(&expr->node, res_node); - return true; - } - return false; + return NULL; } static bool is_op_associative(enum hlsl_ir_expr_op op, enum hlsl_base_type type)