vkd3d-shader/hlsl: Fold "x < 0" to false for unsigned x.

This commit is contained in:
Henri Verbeet
2025-09-18 20:24:58 +02:00
parent 609fb32f53
commit 3e47752c95
Notes: Henri Verbeet 2025-09-22 11:47:29 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1747

View File

@@ -1649,6 +1649,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
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;
@@ -1711,6 +1712,17 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
res_node = &const_arg->node;
break;
case HLSL_OP2_LESS:
/* x < 0 -> false, if x is unsigned. */
if (!hlsl_type_is_unsigned_integer(expr->operands[0].node->data_type)
|| 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;
default:
break;
}