These four patches are the result of going through gcc/* looking for places where there was an obvious mode associated with a GEN_INT and where gen_int_mode could therefore be used instead. Some of the GEN_INTs did create noncanoical rtl before, and were trapped by Kenny's assert on the wide-int branch. However, most of the affected places will be benign. I'm therefore trying to sell this as a cleanup and don't have any testcases.
I've split the patches up based on the reason why the mode is "obvious". In this first patch, the GEN_INTs are all used in calls to gen_rtx_* and are all cases where the operand must have the same mode as the result. (This excludes things like shift count operands, since they can have a different mode from the shifted operand and the result.) Tested on x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ * alias.c (addr_side_effect_eval): Use gen_int_mode with the mode of the associated gen_rtx_* call. * caller-save.c (init_caller_save): Likewise. * combine.c (find_split_point, make_extraction): Likewise. (make_compound_operation): Likewise. * dwarf2out.c (mem_loc_descriptor): Likewise. * explow.c (plus_constant, probe_stack_range): Likewise. * expmed.c (expand_mult_const): Likewise. * expr.c (emit_single_push_insn_1, do_tablejump): Likewise. * reload1.c (init_reload): Likewise. * valtrack.c (cleanup_auto_inc_dec): Likewise. * var-tracking.c (adjust_mems): Likewise. * modulo-sched.c (sms_schedule): Likewise, but use gen_rtx_GT rather than gen_rtx_fmt_ee. Index: gcc/alias.c =================================================================== --- gcc/alias.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/alias.c 2013-09-09 10:49:45.213460712 +0100 @@ -1891,15 +1891,15 @@ addr_side_effect_eval (rtx addr, int siz default: return addr; } if (offset) addr = gen_rtx_PLUS (GET_MODE (addr), XEXP (addr, 0), - GEN_INT (offset)); + gen_int_mode (offset, GET_MODE (addr))); else addr = XEXP (addr, 0); addr = canon_rtx (addr); return addr; } Index: gcc/caller-save.c =================================================================== --- gcc/caller-save.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/caller-save.c 2013-09-09 10:49:45.213460712 +0100 @@ -235,15 +235,15 @@ init_caller_save (void) gcc_assert (i < FIRST_PSEUDO_REGISTER); addr_reg = gen_rtx_REG (Pmode, i); for (offset = 1 << (HOST_BITS_PER_INT / 2); offset; offset >>= 1) { - address = gen_rtx_PLUS (Pmode, addr_reg, GEN_INT (offset)); + address = gen_rtx_PLUS (Pmode, addr_reg, gen_int_mode (offset, Pmode)); for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) if (regno_save_mode[i][1] != VOIDmode && ! strict_memory_address_p (regno_save_mode[i][1], address)) break; if (i == FIRST_PSEUDO_REGISTER) Index: gcc/combine.c =================================================================== --- gcc/combine.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/combine.c 2013-09-09 10:49:45.218460753 +0100 @@ -4721,21 +4721,22 @@ find_split_point (rtx *loc, rtx insn, bo AND or two shifts. Use two shifts for field sizes where the constant might be too large. We assume here that we can always at least get 8-bit constants in an AND insn, which is true for every current RISC. */ if (unsignedp && len <= 8) { + unsigned HOST_WIDE_INT mask + = ((unsigned HOST_WIDE_INT) 1 << len) - 1; SUBST (SET_SRC (x), gen_rtx_AND (mode, gen_rtx_LSHIFTRT (mode, gen_lowpart (mode, inner), GEN_INT (pos)), - GEN_INT (((unsigned HOST_WIDE_INT) 1 << len) - - 1))); + gen_int_mode (mask, mode))); split = find_split_point (&SET_SRC (x), insn, true); if (split && split != &SET_SRC (x)) return split; } else { @@ -4810,17 +4811,19 @@ find_split_point (rtx *loc, rtx insn, bo if (set_src && code == MINUS && GET_CODE (XEXP (x, 1)) == MULT && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT && exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1))) < 0) { enum machine_mode mode = GET_MODE (x); unsigned HOST_WIDE_INT this_int = INTVAL (XEXP (XEXP (x, 1), 1)); HOST_WIDE_INT other_int = trunc_int_for_mode (-this_int, mode); - SUBST (*loc, gen_rtx_PLUS (mode, gen_rtx_MULT (mode, - XEXP (XEXP (x, 1), 0), - GEN_INT (other_int)), + SUBST (*loc, gen_rtx_PLUS (mode, + gen_rtx_MULT (mode, + XEXP (XEXP (x, 1), 0), + gen_int_mode (other_int, + mode)), XEXP (x, 0))); return find_split_point (loc, insn, set_src); } /* Split at a multiply-accumulate instruction. However if this is the SET_SRC, we likely do not have such an instruction and it's worthless to try this split. */ @@ -7254,15 +7257,17 @@ make_extraction (enum machine_mode mode, ? GET_MODE_BITSIZE (is_mode) : GET_MODE_BITSIZE (wanted_inner_mode)); if (pos_rtx == 0) pos = width - len - pos; else pos_rtx - = gen_rtx_MINUS (GET_MODE (pos_rtx), GEN_INT (width - len), pos_rtx); + = gen_rtx_MINUS (GET_MODE (pos_rtx), + gen_int_mode (width - len, GET_MODE (pos_rtx)), + pos_rtx); /* POS may be less than 0 now, but we check for that below. Note that it can only be less than 0 if !MEM_P (inner). */ } /* If INNER has a wider mode, and this is a constant extraction, try to make it smaller and adjust the byte to point to the byte containing the value. */ @@ -7486,15 +7491,15 @@ make_compound_operation (rtx x, enum rtx new_rtx = make_compound_operation (XEXP (x, 0), next_code); if (GET_CODE (new_rtx) == NEG) { new_rtx = XEXP (new_rtx, 0); multval = -multval; } multval = trunc_int_for_mode (multval, mode); - new_rtx = gen_rtx_MULT (mode, new_rtx, GEN_INT (multval)); + new_rtx = gen_rtx_MULT (mode, new_rtx, gen_int_mode (multval, mode)); } break; case PLUS: lhs = XEXP (x, 0); rhs = XEXP (x, 1); lhs = make_compound_operation (lhs, next_code); Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/dwarf2out.c 2013-09-09 10:49:45.225460811 +0100 @@ -12382,17 +12382,18 @@ mem_loc_descriptor (rtx rtl, enum machin goto plus; case PRE_INC: case PRE_DEC: /* Turn these into a PLUS expression and fall into the PLUS code below. */ rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0), - GEN_INT (GET_CODE (rtl) == PRE_INC - ? GET_MODE_UNIT_SIZE (mem_mode) - : -GET_MODE_UNIT_SIZE (mem_mode))); + gen_int_mode (GET_CODE (rtl) == PRE_INC + ? GET_MODE_UNIT_SIZE (mem_mode) + : -GET_MODE_UNIT_SIZE (mem_mode), + mode)); /* ... fall through ... */ case PLUS: plus: if (is_based_loc (rtl) && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE Index: gcc/explow.c =================================================================== --- gcc/explow.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/explow.c 2013-09-09 10:49:45.226460819 +0100 @@ -182,15 +182,15 @@ plus_constant (enum machine_mode mode, r break; default: break; } if (c != 0) - x = gen_rtx_PLUS (mode, x, GEN_INT (c)); + x = gen_rtx_PLUS (mode, x, gen_int_mode (c, mode)); if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF) return x; else if (all_constant) return gen_rtx_CONST (mode, x); else return x; @@ -1637,15 +1637,16 @@ probe_stack_range (HOST_WIDE_INT first, /* Step 2: compute initial and final value of the loop counter. */ /* TEST_ADDR = SP + FIRST. */ test_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode, stack_pointer_rtx, - GEN_INT (first)), NULL_RTX); + gen_int_mode (first, Pmode)), + NULL_RTX); /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */ last_addr = force_operand (gen_rtx_fmt_ee (STACK_GROW_OP, Pmode, test_addr, rounded_size_op), NULL_RTX); Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/expmed.c 2013-09-09 10:49:45.228460835 +0100 @@ -3002,15 +3002,16 @@ expand_mult_const (enum machine_mode mod accum_inner = SUBREG_REG (accum); nmode = GET_MODE (accum_inner); tem = gen_lowpart (nmode, op0); } insn = get_last_insn (); set_dst_reg_note (insn, REG_EQUAL, - gen_rtx_MULT (nmode, tem, GEN_INT (val_so_far)), + gen_rtx_MULT (nmode, tem, + gen_int_mode (val_so_far, nmode)), accum_inner); } } if (variant == negate_variant) { val_so_far = -val_so_far; Index: gcc/expr.c =================================================================== --- gcc/expr.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/expr.c 2013-09-09 10:49:45.230460851 +0100 @@ -3922,26 +3922,28 @@ emit_single_push_insn_1 (enum machine_mo offset += (HOST_WIDE_INT) rounded_size; #else if (STACK_PUSH_CODE == POST_INC) /* We have already incremented the stack pointer, so get the previous value. */ offset -= (HOST_WIDE_INT) rounded_size; #endif - dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset)); + dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, + gen_int_mode (offset, Pmode)); } else { #ifdef STACK_GROWS_DOWNWARD /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */ dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, - GEN_INT (-(HOST_WIDE_INT) rounded_size)); + gen_int_mode (-(HOST_WIDE_INT) rounded_size, + Pmode)); #else /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */ dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, - GEN_INT (rounded_size)); + gen_int_mode (rounded_size, Pmode)); #endif dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr); } dest = gen_rtx_MEM (mode, dest_addr); if (type != 0) @@ -11024,18 +11026,19 @@ do_tablejump (rtx index, enum machine_mo index = copy_to_mode_reg (Pmode, index); #endif /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the GET_MODE_SIZE, because this indicates how large insns are. The other uses should all be Pmode, because they are addresses. This code could fail if addresses and insns are not the same size. */ - index = gen_rtx_PLUS (Pmode, - gen_rtx_MULT (Pmode, index, - GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))), - gen_rtx_LABEL_REF (Pmode, table_label)); + index = gen_rtx_PLUS + (Pmode, + gen_rtx_MULT (Pmode, index, + gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE), Pmode)), + gen_rtx_LABEL_REF (Pmode, table_label)); #ifdef PIC_CASE_VECTOR_ADDRESS if (flag_pic) index = PIC_CASE_VECTOR_ADDRESS (index); else #endif index = memory_address (CASE_VECTOR_MODE, index); temp = gen_reg_rtx (CASE_VECTOR_MODE); Index: gcc/reload1.c =================================================================== --- gcc/reload1.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/reload1.c 2013-09-09 10:49:45.231460860 +0100 @@ -431,15 +431,15 @@ init_reload (void) permitted, zero if it is not permitted at all. */ rtx tem = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, LAST_VIRTUAL_REGISTER + 1), - GEN_INT (4))); + gen_int_mode (4, Pmode))); spill_indirect_levels = 0; while (memory_address_p (QImode, tem)) { spill_indirect_levels++; tem = gen_rtx_MEM (Pmode, tem); } Index: gcc/valtrack.c =================================================================== --- gcc/valtrack.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/valtrack.c 2013-09-09 10:49:45.232460868 +0100 @@ -89,17 +89,18 @@ cleanup_auto_inc_dec (rtx src, enum mach break; case PRE_INC: case PRE_DEC: gcc_assert (mem_mode != VOIDmode && mem_mode != BLKmode); return gen_rtx_PLUS (GET_MODE (x), cleanup_auto_inc_dec (XEXP (x, 0), mem_mode), - GEN_INT (code == PRE_INC - ? GET_MODE_SIZE (mem_mode) - : -GET_MODE_SIZE (mem_mode))); + gen_int_mode (code == PRE_INC + ? GET_MODE_SIZE (mem_mode) + : -GET_MODE_SIZE (mem_mode), + GET_MODE (x))); case POST_INC: case POST_DEC: case PRE_MODIFY: case POST_MODIFY: return cleanup_auto_inc_dec (code == PRE_MODIFY ? XEXP (x, 1) : XEXP (x, 0), Index: gcc/var-tracking.c =================================================================== --- gcc/var-tracking.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/var-tracking.c 2013-09-09 10:49:45.233460877 +0100 @@ -1041,28 +1041,30 @@ adjust_mems (rtx loc, const_rtx old_rtx, mem = replace_equiv_address_nv (mem, addr); if (!amd->store) mem = avoid_constant_pool_reference (mem); return mem; case PRE_INC: case PRE_DEC: addr = gen_rtx_PLUS (GET_MODE (loc), XEXP (loc, 0), - GEN_INT (GET_CODE (loc) == PRE_INC - ? GET_MODE_SIZE (amd->mem_mode) - : -GET_MODE_SIZE (amd->mem_mode))); + gen_int_mode (GET_CODE (loc) == PRE_INC + ? GET_MODE_SIZE (amd->mem_mode) + : -GET_MODE_SIZE (amd->mem_mode), + GET_MODE (loc))); case POST_INC: case POST_DEC: if (addr == loc) addr = XEXP (loc, 0); gcc_assert (amd->mem_mode != VOIDmode && amd->mem_mode != BLKmode); addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data); tem = gen_rtx_PLUS (GET_MODE (loc), XEXP (loc, 0), - GEN_INT ((GET_CODE (loc) == PRE_INC - || GET_CODE (loc) == POST_INC) - ? GET_MODE_SIZE (amd->mem_mode) - : -GET_MODE_SIZE (amd->mem_mode))); + gen_int_mode ((GET_CODE (loc) == PRE_INC + || GET_CODE (loc) == POST_INC) + ? GET_MODE_SIZE (amd->mem_mode) + : -GET_MODE_SIZE (amd->mem_mode), + GET_MODE (loc))); amd->side_effects = alloc_EXPR_LIST (0, gen_rtx_SET (VOIDmode, XEXP (loc, 0), tem), amd->side_effects); return addr; case PRE_MODIFY: Index: gcc/modulo-sched.c =================================================================== --- gcc/modulo-sched.c 2013-09-08 17:18:39.842591328 +0100 +++ gcc/modulo-sched.c 2013-09-09 10:49:45.230460851 +0100 @@ -1711,16 +1711,17 @@ sms_schedule (void) ps->ii, stage_count); print_partial_schedule (ps, dump_file); } /* case the BCT count is not known , Do loop-versioning */ if (count_reg && ! count_init) { - rtx comp_rtx = gen_rtx_fmt_ee (GT, VOIDmode, count_reg, - GEN_INT(stage_count)); + rtx comp_rtx = gen_rtx_GT (VOIDmode, count_reg, + gen_int_mode (stage_count, + GET_MODE (count_reg))); unsigned prob = (PROB_SMS_ENOUGH_ITERATIONS * REG_BR_PROB_BASE) / 100; loop_version (loop, comp_rtx, &condition_bb, prob, prob, REG_BR_PROB_BASE - prob, true); }