MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / RedundantSUMod

Function RedundantSUMod

source/opt/folding_rules.cpp:3839–3857  ·  view source on GitHub ↗

This rule handles modulo from division by 1 or vector 1 (a % 1 => 0).

Source from the content-addressed store, hash-verified

3837
3838// This rule handles modulo from division by 1 or vector 1 (a % 1 => 0).
3839FoldingRule 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.

Callers 1

AddFoldingRulesMethod · 0.85

Calls 10

IsAllInt1Function · 0.85
get_type_mgrMethod · 0.80
GetNullConstIdMethod · 0.80
get_constant_mgrMethod · 0.80
SetOpcodeMethod · 0.80
SetInOperandsMethod · 0.80
sizeMethod · 0.45
opcodeMethod · 0.45
GetTypeMethod · 0.45
type_idMethod · 0.45

Tested by

no test coverage detected