diff options
-rw-r--r-- | src/compiler/nir/nir_instr_set.c | 26 | ||||
-rw-r--r-- | src/compiler/nir/nir_validate.c | 35 |
2 files changed, 41 insertions, 20 deletions
diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index 7dfd3ef1a3e..d53e044c901 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -628,29 +628,15 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2) if (load1->def.bit_size != load2->def.bit_size) return false; - for (unsigned i = 0; i < load1->def.num_components; ++i) { - switch (load1->def.bit_size) { - case 1: + if (load1->def.bit_size == 1) { + for (unsigned i = 0; i < load1->def.num_components; ++i) { if (load1->value[i].b != load2->value[i].b) return false; - break; - case 8: - if (load1->value[i].u8 != load2->value[i].u8) - return false; - break; - case 16: - if (load1->value[i].u16 != load2->value[i].u16) - return false; - break; - case 32: - if (load1->value[i].u32 != load2->value[i].u32) - return false; - break; - case 64: - if (load1->value[i].u64 != load2->value[i].u64) - return false; - break; } + } else { + unsigned size = load1->def.num_components * sizeof(*load1->value); + if (memcmp(load1->value, load2->value, size) != 0) + return false; } return true; } diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index 9a950218208..7746c391abc 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -620,9 +620,44 @@ validate_call_instr(nir_call_instr *instr, validate_state *state) } static void +validate_const_value(nir_const_value *val, unsigned bit_size, + validate_state *state) +{ + /* In order for block copies to work properly for things like instruction + * comparisons and [de]serialization, we require the unused bits of the + * nir_const_value to be zero. + */ + nir_const_value cmp_val; + memset(&cmp_val, 0, sizeof(cmp_val)); + switch (bit_size) { + case 1: + cmp_val.b = val->b; + break; + case 8: + cmp_val.u8 = val->u8; + break; + case 16: + cmp_val.u16 = val->u16; + break; + case 32: + cmp_val.u32 = val->u32; + break; + case 64: + cmp_val.u64 = val->u64; + break; + default: + validate_assert(state, !"Invalid load_const bit size"); + } + validate_assert(state, memcmp(val, &cmp_val, sizeof(cmp_val)) == 0); +} + +static void validate_load_const_instr(nir_load_const_instr *instr, validate_state *state) { validate_ssa_def(&instr->def, state); + + for (unsigned i = 0; i < instr->def.num_components; i++) + validate_const_value(&instr->value[i], instr->def.bit_size, state); } static void |