x - x = 0
| 992 | |
| 993 | // x - x = 0 |
| 994 | ConstantFoldingRule FoldRedundantSub() { |
| 995 | return [](IRContext* context, Instruction* inst, |
| 996 | const std::vector<const analysis::Constant*>&) |
| 997 | -> const analysis::Constant* { |
| 998 | assert(inst->opcode() == spv::Op::OpFSub || |
| 999 | inst->opcode() == spv::Op::OpISub); |
| 1000 | |
| 1001 | if (inst->GetSingleWordInOperand(0) == inst->GetSingleWordInOperand(1)) { |
| 1002 | bool use_float = inst->opcode() == spv::Op::OpFSub; |
| 1003 | if (use_float && !inst->IsFloatingPointFoldingAllowed()) { |
| 1004 | return nullptr; |
| 1005 | } |
| 1006 | analysis::TypeManager* type_mgr = context->get_type_mgr(); |
| 1007 | const analysis::Type* type = type_mgr->GetType(inst->type_id()); |
| 1008 | if (type->IsCooperativeMatrix()) { |
| 1009 | return nullptr; |
| 1010 | } |
| 1011 | analysis::ConstantManager* const_mgr = context->get_constant_mgr(); |
| 1012 | uint32_t null_id = const_mgr->GetNullConstId(type); |
| 1013 | return const_mgr->FindDeclaredConstant(null_id); |
| 1014 | } |
| 1015 | return nullptr; |
| 1016 | }; |
| 1017 | } |
| 1018 | |
| 1019 | // Returns the constant that results from evaluating |numerator| / 0.0. Returns |
| 1020 | // |nullptr| if the result could not be evaluated. |
no test coverage detected