This rule handles modulo from division by 1 or vector 1 (a % 1 => 0).
| 3837 | |
| 3838 | // This rule handles modulo from division by 1 or vector 1 (a % 1 => 0). |
| 3839 | FoldingRule RedundantSUMod() { |
| 3840 | return [](IRContext* context, Instruction* inst, |
| 3841 | const std::vector<const analysis::Constant*>& constants) { |
| 3842 | assert(constants.size() == 2); |
| 3843 | assert((inst->opcode() == spv::Op::OpUMod || |
| 3844 | inst->opcode() == spv::Op::OpSMod) && |
| 3845 | "Wrong opcode."); |
| 3846 | |
| 3847 | if (constants[1] && IsAllInt1(constants[1])) { |
| 3848 | auto type = context->get_type_mgr()->GetType(inst->type_id()); |
| 3849 | auto zero_id = context->get_constant_mgr()->GetNullConstId(type); |
| 3850 | |
| 3851 | inst->SetOpcode(spv::Op::OpCopyObject); |
| 3852 | inst->SetInOperands({{SPV_OPERAND_TYPE_ID, {zero_id}}}); |
| 3853 | return true; |
| 3854 | } |
| 3855 | return false; |
| 3856 | }; |
| 3857 | } |
| 3858 | |
| 3859 | // Utility function for applying |callback| to |input1| and |input2|. |
| 3860 | // If they are vectors it applies element wise. |
no test coverage detected