ldstopt: fix for case of non-const global initializer
authorMatthias Braun <matze@braunis.de>
Mon, 19 Nov 2012 16:10:42 +0000 (17:10 +0100)
committerMatthias Braun <matze@braunis.de>
Mon, 19 Nov 2012 16:12:19 +0000 (17:12 +0100)
ir/opt/ldstopt.c

index aad7905..bccb388 100644 (file)
@@ -1007,10 +1007,16 @@ static unsigned optimize_load(ir_node *load)
                                        /* frontend has inserted masking operations after bitfield accesses,
                                         * so we might have to shift the const. */
                                        unsigned char bit_offset = get_entity_offset_bits_remainder(get_Sel_entity(ptr));
-                                       ir_tarval *tv_old = get_Const_tarval(value);
-                                       ir_tarval *tv_offset = new_tarval_from_long(bit_offset, mode_Bu);
-                                       ir_tarval *tv_new = tarval_shl(tv_old, tv_offset);
-                                       value = new_r_Const(irg, tv_new);
+                                       if (bit_offset != 0) {
+                                               if (is_Const(value)) {
+                                                       ir_tarval *tv_old = get_Const_tarval(value);
+                                                       ir_tarval *tv_offset = new_tarval_from_long(bit_offset, mode_Bu);
+                                                       ir_tarval *tv_new = tarval_shl(tv_old, tv_offset);
+                                                       value = new_r_Const(irg, tv_new);
+                                               } else {
+                                                       value = NULL;
+                                               }
+                                       }
                                }
                        }
                }