| 2024 | } |
| 2025 | |
| 2026 | FoldingRule IntMultipleBy1() { |
| 2027 | return [](IRContext*, Instruction* inst, |
| 2028 | const std::vector<const analysis::Constant*>& constants) { |
| 2029 | assert(inst->opcode() == spv::Op::OpIMul && |
| 2030 | "Wrong opcode. Should be OpIMul."); |
| 2031 | for (uint32_t i = 0; i < 2; i++) { |
| 2032 | if (constants[i] == nullptr) { |
| 2033 | continue; |
| 2034 | } |
| 2035 | const analysis::IntConstant* int_constant = constants[i]->AsIntConstant(); |
| 2036 | if (int_constant) { |
| 2037 | uint32_t width = ElementWidth(int_constant->type()); |
| 2038 | if (width != 32 && width != 64) return false; |
| 2039 | bool is_one = (width == 32) ? int_constant->GetU32BitValue() == 1u |
| 2040 | : int_constant->GetU64BitValue() == 1ull; |
| 2041 | if (is_one) { |
| 2042 | inst->SetOpcode(spv::Op::OpCopyObject); |
| 2043 | inst->SetInOperands( |
| 2044 | {{SPV_OPERAND_TYPE_ID, {inst->GetSingleWordInOperand(1 - i)}}}); |
| 2045 | return true; |
| 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | return false; |
| 2050 | }; |
| 2051 | } |
| 2052 | |
| 2053 | // Returns the number of elements that the |index|th in operand in |inst| |
| 2054 | // contributes to the result of |inst|. |inst| must be an |
no test coverage detected