spirv-diff: Handle OpSpecConstant array sizes (#4700)

Previously, array sizes were presumed to be OpConstant, which is not
necessarily true.  This change ensures OpSpecConstant array sizes as
matched exactly, instead of taken as OpConstant and matched by value.
This commit is contained in:
Shahbaz Youssefi
2022-02-09 09:06:46 -05:00
committed by GitHub
parent 3d957a6d00
commit 71a7e84784
8 changed files with 826 additions and 7 deletions
+18 -7
View File
@@ -307,6 +307,7 @@ class Differ {
const opt::Operand& dst_operand);
bool DoInstructionsMatchFuzzy(const opt::Instruction* src_inst,
const opt::Instruction* dst_inst);
bool AreIdenticalUintConstants(uint32_t src_id, uint32_t dst_id);
bool DoDebugAndAnnotationInstructionsMatch(const opt::Instruction* src_inst,
const opt::Instruction* dst_inst);
bool AreVariablesMatchable(uint32_t src_id, uint32_t dst_id,
@@ -840,10 +841,8 @@ bool Differ::DoIdsMatchFuzzy(uint32_t src_id, uint32_t dst_id) {
}
// Int and Uint constants are interchangeable, match them in that case.
if (IsConstantUint(src_id_to_, src_id) &&
IsConstantUint(dst_id_to_, dst_id)) {
return GetConstantUint(src_id_to_, src_id) ==
GetConstantUint(dst_id_to_, dst_id);
if (AreIdenticalUintConstants(src_id, dst_id)) {
return true;
}
return false;
@@ -911,6 +910,13 @@ bool Differ::DoInstructionsMatchFuzzy(const opt::Instruction* src_inst,
return match;
}
bool Differ::AreIdenticalUintConstants(uint32_t src_id, uint32_t dst_id) {
return IsConstantUint(src_id_to_, src_id) &&
IsConstantUint(dst_id_to_, dst_id) &&
GetConstantUint(src_id_to_, src_id) ==
GetConstantUint(dst_id_to_, dst_id);
}
bool Differ::DoDebugAndAnnotationInstructionsMatch(
const opt::Instruction* src_inst, const opt::Instruction* dst_inst) {
if (src_inst->opcode() != dst_inst->opcode()) {
@@ -2001,9 +2007,14 @@ void Differ::MatchTypeIds() {
return false;
}
return GetConstantUint(src_id_to_,
src_inst->GetInOperand(1).AsId()) ==
GetConstantUint(dst_id_to_, dst_inst->GetInOperand(1).AsId());
if (AreIdenticalUintConstants(src_inst->GetInOperand(1).AsId(),
dst_inst->GetInOperand(1).AsId())) {
return true;
}
// If size is not OpConstant, expect the ids to match exactly (for
// example if a spec contant is used).
return DoOperandsMatch(src_inst, dst_inst, 1, 1);
case SpvOpTypeStruct:
return MatchOpTypeStruct(src_inst, dst_inst, flexibility);