Folds addition of a subtraction where the subtrahend is equal to the other addend. Return a copy of the minuend. Accepts generic (const and non-const) operands. Cases: (a - b) + b = a b + (a - b) = a
| 1532 | // (a - b) + b = a |
| 1533 | // b + (a - b) = a |
| 1534 | FoldingRule MergeGenericAddSubArithmetic() { |
| 1535 | return [](IRContext* context, Instruction* inst, |
| 1536 | const std::vector<const analysis::Constant*>&) { |
| 1537 | assert(inst->opcode() == spv::Op::OpFAdd || |
| 1538 | inst->opcode() == spv::Op::OpIAdd); |
| 1539 | const analysis::Type* type = |
| 1540 | context->get_type_mgr()->GetType(inst->type_id()); |
| 1541 | |
| 1542 | if (type->IsCooperativeMatrix()) { |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
| 1546 | bool uses_float = HasFloatingPoint(type); |
| 1547 | if (uses_float && !inst->IsFloatingPointFoldingAllowed()) return false; |
| 1548 | |
| 1549 | uint32_t width = ElementWidth(type); |
| 1550 | if (width != 32 && width != 64) return false; |
| 1551 | |
| 1552 | uint32_t add_op0 = inst->GetSingleWordInOperand(0); |
| 1553 | uint32_t add_op1 = inst->GetSingleWordInOperand(1); |
| 1554 | if (MergeGenericAddendSub(add_op0, add_op1, inst)) return true; |
| 1555 | return MergeGenericAddendSub(add_op1, add_op0, inst); |
| 1556 | }; |
| 1557 | } |
| 1558 | |
| 1559 | // Helper function for FactorAddSubMuls. |
| 1560 | // If |factor0_0| is the same as |factor1_0|, generate: |
no test coverage detected