+// Check if the value can be reused from a previous value. If so, copy the
+// `m_code` segment and return `true`. Othrewise return false and, if the value
+// is eligable to be reused later, record it in `m_reusable_const_floats`.
+bool ir_builder::generateMergedFloat(ir_value *global, bool register_only)
+{
+ if ((global->m_flags & IR_FLAG_INCLUDE_DEF)
+ || global->m_callparam || global->m_locked || global->m_unique_life
+ || global->m_memberof
+ || global->m_members[0]
+ || global->m_members[1]
+ || global->m_members[2]
+ || global->m_store != store_global
+ )
+ {
+ return false;
+ }
+
+ if (!global->m_writes.empty()) {
+ irerror(global->m_context, "writing to a global const");
+ return false;
+ }
+
+ auto old = m_reusable_const_floats.find(global->m_constval.vint);
+ if (old == m_reusable_const_floats.end()) {
+ auto iptr = (int32_t*)&global->m_constval.ivec[0];
+ m_reusable_const_floats[*iptr] = global;
+ return false;
+ } else if (register_only) {
+ return false;
+ } else {
+ global->m_code = old->second->m_code;
+ return true;
+ }
+}
+