Elides consecutive negate instructions.
| 405 | |
| 406 | // Elides consecutive negate instructions. |
| 407 | FoldingRule MergeNegateArithmetic() { |
| 408 | return [](IRContext* context, Instruction* inst, |
| 409 | const std::vector<const analysis::Constant*>& constants) { |
| 410 | assert(inst->opcode() == spv::Op::OpFNegate || |
| 411 | inst->opcode() == spv::Op::OpSNegate); |
| 412 | (void)constants; |
| 413 | const analysis::Type* type = |
| 414 | context->get_type_mgr()->GetType(inst->type_id()); |
| 415 | if (HasFloatingPoint(type) && !inst->IsFloatingPointFoldingAllowed()) |
| 416 | return false; |
| 417 | |
| 418 | Instruction* op_inst = |
| 419 | context->get_def_use_mgr()->GetDef(inst->GetSingleWordInOperand(0u)); |
| 420 | if (HasFloatingPoint(type) && !op_inst->IsFloatingPointFoldingAllowed()) |
| 421 | return false; |
| 422 | |
| 423 | if (op_inst->opcode() == inst->opcode()) { |
| 424 | // Elide negates. |
| 425 | inst->SetOpcode(spv::Op::OpCopyObject); |
| 426 | inst->SetInOperands( |
| 427 | {{SPV_OPERAND_TYPE_ID, {op_inst->GetSingleWordInOperand(0u)}}}); |
| 428 | return true; |
| 429 | } |
| 430 | |
| 431 | return false; |
| 432 | }; |
| 433 | } |
| 434 | |
| 435 | // Merges negate into a mul or div operation if that operation contains a |
| 436 | // constant operand. |
no test coverage detected