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

Function MergeGenericAddendSub

source/opt/folding_rules.cpp:1510–1526  ·  view source on GitHub ↗

Helper function for MergeGenericAddSubArithmetic. If |addend| and subtrahend of |sub| is the same, merge to copy of minuend of |sub|.

Source from the content-addressed store, hash-verified

1508// Helper function for MergeGenericAddSubArithmetic. If |addend| and
1509// subtrahend of |sub| is the same, merge to copy of minuend of |sub|.
1510bool MergeGenericAddendSub(uint32_t addend, uint32_t sub, Instruction* inst) {
1511 IRContext* context = inst->context();
1512 analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1513 Instruction* sub_inst = def_use_mgr->GetDef(sub);
1514 if (sub_inst->opcode() != spv::Op::OpFSub &&
1515 sub_inst->opcode() != spv::Op::OpISub)
1516 return false;
1517 if (sub_inst->opcode() == spv::Op::OpFSub &&
1518 !sub_inst->IsFloatingPointFoldingAllowed())
1519 return false;
1520 if (addend != sub_inst->GetSingleWordInOperand(1)) return false;
1521 inst->SetOpcode(spv::Op::OpCopyObject);
1522 inst->SetInOperands(
1523 {{SPV_OPERAND_TYPE_ID, {sub_inst->GetSingleWordInOperand(0)}}});
1524 context->UpdateDefUse(inst);
1525 return true;
1526}
1527
1528// Folds addition of a subtraction where the subtrahend is equal to the
1529// other addend. Return a copy of the minuend. Accepts generic (const and

Callers 1

Calls 9

SetOpcodeMethod · 0.80
SetInOperandsMethod · 0.80
contextMethod · 0.45
get_def_use_mgrMethod · 0.45
GetDefMethod · 0.45
opcodeMethod · 0.45
UpdateDefUseMethod · 0.45

Tested by

no test coverage detected