diff --git a/source/opt/folding_rules.cpp b/source/opt/folding_rules.cpp index 293236d9f22..d9ffc46ff74 100644 --- a/source/opt/folding_rules.cpp +++ b/source/opt/folding_rules.cpp @@ -2079,6 +2079,7 @@ uint32_t GetNumberOfElements(const analysis::Type* type) { return static_cast(struct_type->element_types().size()); } if (auto* array_type = type->AsArray()) { + // STEVEN: This is incorrect return array_type->length_info().words[0]; } return 0; @@ -2086,14 +2087,14 @@ uint32_t GetNumberOfElements(const analysis::Type* type) { // Returns a map with the set of values that were inserted into an object by // the chain of OpCompositeInsertInstruction starting with |inst|. -// The map will map the index to the value inserted at that index. +// The map will map the index to the value inserted at that index. An empty map will be returned if the map could not be properly generated. std::map GetInsertedValues(Instruction* inst) { analysis::DefUseManager* def_use_mgr = inst->context()->get_def_use_mgr(); std::map values_inserted; Instruction* current_inst = inst; while (current_inst->opcode() == spv::Op::OpCompositeInsert) { if (current_inst->NumInOperands() > inst->NumInOperands()) { - // This is the catch the case + // This is to catch the case // %2 = OpCompositeInsert %m2x2int %v2int_1_0 %m2x2int_undef 0 // %3 = OpCompositeInsert %m2x2int %int_4 %2 0 0 // %4 = OpCompositeInsert %m2x2int %v2int_2_3 %3 1 @@ -2124,6 +2125,8 @@ bool DoInsertedValuesCoverEntireObject( return false; } + std::cerr << container_size << ", " << values_inserted.size() << "\n"; + if (values_inserted.rbegin()->first >= container_size) { return false; } @@ -2183,6 +2186,10 @@ bool CompositeInsertToCompositeConstruct( if (inst->NumInOperands() < 3) return false; std::map values_inserted = GetInsertedValues(inst); + if (values_inserted.empty()) { + // return false; + } + const analysis::Type* container_type = GetContainerType(inst); if (container_type == nullptr) { return false;