Negates the vector constant |c|. Returns the id of the defining instruction.
| 286 | |
| 287 | // Negates the vector constant |c|. Returns the id of the defining instruction. |
| 288 | uint32_t NegateVectorConstant(analysis::ConstantManager* const_mgr, |
| 289 | const analysis::Constant* c) { |
| 290 | assert(const_mgr && c); |
| 291 | assert(c->type()->AsVector()); |
| 292 | if (c->AsNullConstant()) { |
| 293 | // 0.0 vs -0.0 shouldn't matter. |
| 294 | return const_mgr->GetDefiningInstruction(c)->result_id(); |
| 295 | } else { |
| 296 | const analysis::Type* component_type = |
| 297 | c->AsVectorConstant()->component_type(); |
| 298 | std::vector<uint32_t> words; |
| 299 | for (auto& comp : c->AsVectorConstant()->GetComponents()) { |
| 300 | if (component_type->AsFloat()) { |
| 301 | words.push_back(NegateFloatingPointConstant(const_mgr, comp)); |
| 302 | } else { |
| 303 | assert(component_type->AsInteger()); |
| 304 | words.push_back(NegateIntegerConstant(const_mgr, comp)); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | const analysis::Constant* negated_const = |
| 309 | const_mgr->GetConstant(c->type(), std::move(words)); |
| 310 | return const_mgr->GetDefiningInstruction(negated_const)->result_id(); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // Negates |c|. Returns the id of the defining instruction. |
| 315 | uint32_t NegateConstant(analysis::ConstantManager* const_mgr, |
no test coverage detected