This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC] Curious REG_EQUAL note for multiplication
- From: Kaz Kojima <kkojima at rr dot iij4u dot or dot jp>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 17 May 2009 07:38:36 +0900 (JST)
- Subject: [RFC] Curious REG_EQUAL note for multiplication
Hi,
PR 40154 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40154
is reported for SH with -O and is a 4.4/4.5 regression on this
target. The test case looks like
long long t = 50;
...
t *= 1000000000;
...
and the .expand rtl dump shows that t *= 1000000000 is compiled
to a sequence of insns of which the last two insns are:
(insn 87 86 88 ice.i:6 (parallel [
(set (subreg:SI (reg:DI 220) 0)
(ashift:SI (subreg:SI (reg:DI 218) 0)
(const_int 9 [0x9])))
(clobber (scratch:SI))
]) -1 (expr_list:REG_EQUAL (mult:DI (reg:DI 169)
(const_int 1000000000 [0x3b9aca00]))
(nil)))
(insn 88 87 0 ice.i:6 (set (mem/c/i:DI (plus:SI (reg/f:SI 167)
(const_int 56 [0x38])) [0 t+0 S8 A32])
(reg:DI 220)) -1 (nil))
Then CSE pass folds the constant multiplication and replaces
the above insn 87 with
(insn 87 86 108 2 ice.i:6 (set (reg:SI 229)
(const_int -1539607552 [0xffffffffa43b7400])) 175 {movsi_ie} (expr_list:REG_EQUAL (const_int 50000000000 [0xba43b7400])
(nil)))
and do_SUBST complains that a SImode reg can't hold 50000000000
at the combine pass.
I guess that the REG_EQUAL note of the original insn 87 is a bit
suspicious and it seems that the patch below avoids the problem.
It's regtested on i686-pc-linux-gnu, though it may be a wrong
approach. I'm happy to get comments from middle-end experts.
Regards,
kaz
--
* expmed.c (expand_mult_const): Add a REG_EQUAL note only if
the mode of the result of the multiplication is consistent
with that of the insn.
--- ORIG/trunk/gcc/expmed.c 2009-05-12 19:17:54.000000000 +0900
+++ trunk/gcc/expmed.c 2009-05-16 08:34:14.000000000 +0900
@@ -2958,7 +2958,7 @@ expand_mult_const (enum machine_mode mod
enum mult_variant variant)
{
HOST_WIDE_INT val_so_far;
- rtx insn, accum, tem;
+ rtx insn, accum, tem, set;
int opno;
enum machine_mode nmode;
@@ -3074,9 +3074,12 @@ expand_mult_const (enum machine_mode mod
}
insn = get_last_insn ();
- set_unique_reg_note (insn, REG_EQUAL,
- gen_rtx_MULT (nmode, tem,
- GEN_INT (val_so_far)));
+ set = single_set (insn);
+ if (set != 0
+ && GET_MODE (SET_DEST (set)) == nmode)
+ set_unique_reg_note (insn, REG_EQUAL,
+ gen_rtx_MULT (nmode, tem,
+ GEN_INT (val_so_far)));
}
if (variant == negate_variant)