| 1256 | } |
| 1257 | |
| 1258 | ConstantFoldingRule 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. |
no test coverage detected