+/* Returns true if a value of mode sm can be converted into mode lm
+ and backwards without loss. */
+int values_in_mode(const ir_mode *sm, const ir_mode *lm) {
+ int sm_bits, lm_bits;
+ ir_mode_arithmetic arith;
+
+ assert(sm);
+ assert(lm);
+
+ if (sm == lm) return 1;
+
+ if (sm == mode_b)
+ return mode_is_int(lm);
+
+ sm_bits = get_mode_size_bits(sm);
+ lm_bits = get_mode_size_bits(lm);
+
+ arith = get_mode_arithmetic(sm);
+ if (arith != get_mode_arithmetic(lm))
+ return 0;
+
+ switch (arith) {
+ case irma_twos_complement:
+ case irma_ieee754:
+ return get_mode_size_bits(sm) <= get_mode_size_bits(lm);
+
+ default:
+ return 0;
+ }
+}
+