MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / IntMultipleBy1

Function IntMultipleBy1

source/opt/folding_rules.cpp:2026–2051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2024}
2025
2026FoldingRule 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

Callers 1

AddFoldingRulesMethod · 0.85

Calls 9

ElementWidthFunction · 0.85
GetU32BitValueMethod · 0.80
GetU64BitValueMethod · 0.80
SetOpcodeMethod · 0.80
SetInOperandsMethod · 0.80
opcodeMethod · 0.45
AsIntConstantMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected