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

Function FoldRedundantSub

source/opt/const_folding_rules.cpp:994–1017  ·  view source on GitHub ↗

x - x = 0

Source from the content-addressed store, hash-verified

992
993// x - x = 0
994ConstantFoldingRule 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.

Callers 1

AddFoldingRulesMethod · 0.85

Calls 10

get_type_mgrMethod · 0.80
IsCooperativeMatrixMethod · 0.80
get_constant_mgrMethod · 0.80
GetNullConstIdMethod · 0.80
opcodeMethod · 0.45
GetTypeMethod · 0.45
type_idMethod · 0.45
FindDeclaredConstantMethod · 0.45

Tested by

no test coverage detected