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

Function FactorAddSubMulsOpnds

source/opt/folding_rules.cpp:1563–1584  ·  view source on GitHub ↗

Helper function for FactorAddSubMuls. If |factor0_0| is the same as |factor1_0|, generate: |factor0_0| * (|factor0_1| + |factor1_1|) |factor0_0| * (|factor0_1| - |factor1_1|)

Source from the content-addressed store, hash-verified

1561// |factor0_0| * (|factor0_1| + |factor1_1|)
1562// |factor0_0| * (|factor0_1| - |factor1_1|)
1563bool FactorAddSubMulsOpnds(uint32_t factor0_0, uint32_t factor0_1,
1564 uint32_t factor1_0, uint32_t factor1_1,
1565 Instruction* inst) {
1566 IRContext* context = inst->context();
1567 if (factor0_0 != factor1_0) return false;
1568 InstructionBuilder ir_builder(
1569 context, inst,
1570 IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
1571 Instruction* new_add_inst = ir_builder.AddBinaryOp(
1572 inst->type_id(), inst->opcode(), factor0_1, factor1_1);
1573 if (!new_add_inst) {
1574 return false;
1575 }
1576
1577 bool is_float =
1578 inst->opcode() == spv::Op::OpFAdd || inst->opcode() == spv::Op::OpFSub;
1579 inst->SetOpcode(is_float ? spv::Op::OpFMul : spv::Op::OpIMul);
1580 inst->SetInOperands({{SPV_OPERAND_TYPE_ID, {factor0_0}},
1581 {SPV_OPERAND_TYPE_ID, {new_add_inst->result_id()}}});
1582 context->UpdateDefUse(inst);
1583 return true;
1584}
1585
1586// Perform the following factoring identity, handling all operand order
1587// combinations:

Callers 1

FactorAddSubMulsFunction · 0.85

Calls 8

AddBinaryOpMethod · 0.80
SetOpcodeMethod · 0.80
SetInOperandsMethod · 0.80
contextMethod · 0.45
type_idMethod · 0.45
opcodeMethod · 0.45
result_idMethod · 0.45
UpdateDefUseMethod · 0.45

Tested by

no test coverage detected