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

Function FoldInvariantSelect

source/opt/const_folding_rules.cpp:1258–1276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1256}
1257
1258ConstantFoldingRule FoldInvariantSelect() {
1259 return [](IRContext*, Instruction* inst,
1260 const std::vector<const analysis::Constant*>& constants)
1261 -> const analysis::Constant* {
1262 assert(inst->opcode() == spv::Op::OpSelect);
1263 (void)inst;
1264
1265 if (!constants[1] || !constants[2]) {
1266 return nullptr;
1267 }
1268 if (constants[1] == constants[2]) {
1269 return constants[1];
1270 }
1271 if (constants[1]->IsZero() && constants[2]->IsZero()) {
1272 return constants[1];
1273 }
1274 return nullptr;
1275 };
1276}
1277
1278// Folds an OpDot where all of the inputs are constants to a
1279// constant. A new constant is created if necessary.

Callers 1

AddFoldingRulesMethod · 0.85

Calls 2

opcodeMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected