vkd3d-shader/hlsl: Fold logic AND and logic OR identities.

This commit is contained in:
Victor Chiletto 2024-08-22 12:07:46 -03:00 committed by Henri Verbeet
parent d507acb5ac
commit a39227c79c
Notes: Henri Verbeet 2024-09-03 17:17:53 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1014

View File

@ -1452,11 +1452,15 @@ static bool constant_is_one(struct hlsl_ir_constant *const_arg)
case HLSL_TYPE_UINT: case HLSL_TYPE_UINT:
case HLSL_TYPE_INT: case HLSL_TYPE_INT:
case HLSL_TYPE_BOOL:
if (const_arg->value.u[k].u != 1) if (const_arg->value.u[k].u != 1)
return false; return false;
break; break;
case HLSL_TYPE_BOOL:
if (const_arg->value.u[k].u != ~0)
return false;
break;
default: default:
return false; return false;
} }
@ -1514,6 +1518,20 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
res_node = mut_arg; res_node = mut_arg;
break; break;
case HLSL_OP2_LOGIC_AND:
if (constant_is_zero(const_arg))
res_node = &const_arg->node;
else if (constant_is_one(const_arg))
res_node = mut_arg;
break;
case HLSL_OP2_LOGIC_OR:
if (constant_is_zero(const_arg))
res_node = mut_arg;
else if (constant_is_one(const_arg))
res_node = &const_arg->node;
break;
default: default:
break; break;
} }