Helper function for MergeGenericAddSubArithmetic. If |addend| and subtrahend of |sub| is the same, merge to copy of minuend of |sub|.
| 1508 | // Helper function for MergeGenericAddSubArithmetic. If |addend| and |
| 1509 | // subtrahend of |sub| is the same, merge to copy of minuend of |sub|. |
| 1510 | bool 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 |
no test coverage detected