This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lno, mainline] Fix for PR 15274
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 9 May 2004 17:12:30 +0200
- Subject: [lno, mainline] Fix for PR 15274
Hello,
this patch fixes PR 15274 (integer constants being used without
applying trunc_int_for_mode on them).
I have commited it to lno-branch. OK also for mainline?
Zdenek
* loop-iv.c (determine_max_iter, shorten_into_mode,
iv_number_of_iterations): Handle constants correctly.
* rtl.h (get_mode_bounds): Declaration changed. Duplicate declaration
removed.
* stor-layout.c (get_mode_bounds): Return a constant suitable for
a target mode.
Index: loop-iv.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop-iv.c,v
retrieving revision 1.1.4.9
diff -c -3 -p -r1.1.4.9 loop-iv.c
*** loop-iv.c 9 Apr 2004 19:12:50 -0000 1.1.4.9
--- loop-iv.c 9 May 2004 15:05:43 -0000
*************** determine_max_iter (struct niter_desc *d
*** 1203,1209 ****
}
}
! get_mode_bounds (desc->mode, desc->signed_p, &mmin, &mmax);
nmax = INTVAL (mmax) - INTVAL (mmin);
if (GET_CODE (niter) == UDIV)
--- 1203,1209 ----
}
}
! get_mode_bounds (desc->mode, desc->signed_p, desc->mode, &mmin, &mmax);
nmax = INTVAL (mmax) - INTVAL (mmin);
if (GET_CODE (niter) == UDIV)
*************** shorten_into_mode (struct rtx_iv *iv, en
*** 1696,1702 ****
{
rtx mmin, mmax, cond_over, cond_under;
! get_mode_bounds (mode, signed_p, &mmin, &mmax);
cond_under = simplify_gen_relational (LT, SImode, iv->extend_mode,
iv->base, mmin);
cond_over = simplify_gen_relational (GT, SImode, iv->extend_mode,
--- 1696,1702 ----
{
rtx mmin, mmax, cond_over, cond_under;
! get_mode_bounds (mode, signed_p, iv->extend_mode, &mmin, &mmax);
cond_under = simplify_gen_relational (LT, SImode, iv->extend_mode,
iv->base, mmin);
cond_over = simplify_gen_relational (GT, SImode, iv->extend_mode,
*************** iv_number_of_iterations (struct loop *lo
*** 1873,1879 ****
rtx assumption;
enum rtx_code cond;
enum machine_mode mode, comp_mode;
! rtx mmin, mmax;
unsigned HOST_WIDEST_INT s, size, d, inv;
HOST_WIDEST_INT up, down, inc;
int was_sharp = false;
--- 1873,1879 ----
rtx assumption;
enum rtx_code cond;
enum machine_mode mode, comp_mode;
! rtx mmin, mmax, mode_mmin, mode_mmax;
unsigned HOST_WIDEST_INT s, size, d, inv;
HOST_WIDEST_INT up, down, inc;
int was_sharp = false;
*************** iv_number_of_iterations (struct loop *lo
*** 1959,1965 ****
comp_mode = iv0.extend_mode;
mode = iv0.mode;
size = GET_MODE_BITSIZE (mode);
! get_mode_bounds (mode, (cond == LE || cond == LT), &mmin, &mmax);
if (GET_CODE (iv0.step) != CONST_INT || GET_CODE (iv1.step) != CONST_INT)
goto fail;
--- 1959,1967 ----
comp_mode = iv0.extend_mode;
mode = iv0.mode;
size = GET_MODE_BITSIZE (mode);
! get_mode_bounds (mode, (cond == LE || cond == LT), comp_mode, &mmin, &mmax);
! mode_mmin = lowpart_subreg (mode, mmin, comp_mode);
! mode_mmax = lowpart_subreg (mode, mmax, comp_mode);
if (GET_CODE (iv0.step) != CONST_INT || GET_CODE (iv1.step) != CONST_INT)
goto fail;
*************** iv_number_of_iterations (struct loop *lo
*** 2001,2007 ****
if (iv0.step == const0_rtx)
{
tmp = lowpart_subreg (mode, iv0.base, comp_mode);
! assumption = simplify_gen_relational (EQ, SImode, mode, tmp, mmax);
if (assumption == const_true_rtx)
goto zero_iter;
iv0.base = simplify_gen_binary (PLUS, comp_mode,
--- 2003,2010 ----
if (iv0.step == const0_rtx)
{
tmp = lowpart_subreg (mode, iv0.base, comp_mode);
! assumption = simplify_gen_relational (EQ, SImode, mode, tmp,
! mode_mmax);
if (assumption == const_true_rtx)
goto zero_iter;
iv0.base = simplify_gen_binary (PLUS, comp_mode,
*************** iv_number_of_iterations (struct loop *lo
*** 2010,2016 ****
else
{
tmp = lowpart_subreg (mode, iv1.base, comp_mode);
! assumption = simplify_gen_relational (EQ, SImode, mode, tmp, mmin);
if (assumption == const_true_rtx)
goto zero_iter;
iv1.base = simplify_gen_binary (PLUS, comp_mode,
--- 2013,2020 ----
else
{
tmp = lowpart_subreg (mode, iv1.base, comp_mode);
! assumption = simplify_gen_relational (EQ, SImode, mode, tmp,
! mode_mmin);
if (assumption == const_true_rtx)
goto zero_iter;
iv1.base = simplify_gen_binary (PLUS, comp_mode,
*************** iv_number_of_iterations (struct loop *lo
*** 2035,2041 ****
if (iv0.step == const0_rtx)
{
tmp = lowpart_subreg (mode, iv0.base, comp_mode);
! if (rtx_equal_p (tmp, mmin))
{
desc->infinite =
alloc_EXPR_LIST (0, const_true_rtx, NULL_RTX);
--- 2039,2045 ----
if (iv0.step == const0_rtx)
{
tmp = lowpart_subreg (mode, iv0.base, comp_mode);
! if (rtx_equal_p (tmp, mode_mmin))
{
desc->infinite =
alloc_EXPR_LIST (0, const_true_rtx, NULL_RTX);
*************** iv_number_of_iterations (struct loop *lo
*** 2045,2051 ****
else
{
tmp = lowpart_subreg (mode, iv1.base, comp_mode);
! if (rtx_equal_p (tmp, mmax))
{
desc->infinite =
alloc_EXPR_LIST (0, const_true_rtx, NULL_RTX);
--- 2049,2055 ----
else
{
tmp = lowpart_subreg (mode, iv1.base, comp_mode);
! if (rtx_equal_p (tmp, mode_mmax))
{
desc->infinite =
alloc_EXPR_LIST (0, const_true_rtx, NULL_RTX);
*************** iv_number_of_iterations (struct loop *lo
*** 2122,2129 ****
if (GET_CODE (iv1.base) == CONST_INT)
up = INTVAL (iv1.base);
else
! up = INTVAL (mmax) - inc;
! down = INTVAL (GET_CODE (iv0.base) == CONST_INT ? iv0.base : mmin);
desc->niter_max = (up - down) / inc + 1;
if (iv0.step == const0_rtx)
--- 2126,2135 ----
if (GET_CODE (iv1.base) == CONST_INT)
up = INTVAL (iv1.base);
else
! up = INTVAL (mode_mmax) - inc;
! down = INTVAL (GET_CODE (iv0.base) == CONST_INT
! ? iv0.base
! : mode_mmin);
desc->niter_max = (up - down) / inc + 1;
if (iv0.step == const0_rtx)
*************** iv_number_of_iterations (struct loop *lo
*** 2205,2211 ****
tmp0 = lowpart_subreg (mode, iv0.base, comp_mode);
tmp1 = lowpart_subreg (mode, iv1.base, comp_mode);
! bound = simplify_gen_binary (MINUS, mode, mmax, step);
assumption = simplify_gen_relational (cond, SImode, mode,
tmp1, bound);
desc->assumptions =
--- 2211,2218 ----
tmp0 = lowpart_subreg (mode, iv0.base, comp_mode);
tmp1 = lowpart_subreg (mode, iv1.base, comp_mode);
! bound = simplify_gen_binary (MINUS, mode, mode_mmax,
! lowpart_subreg (mode, step, comp_mode));
assumption = simplify_gen_relational (cond, SImode, mode,
tmp1, bound);
desc->assumptions =
*************** iv_number_of_iterations (struct loop *lo
*** 2228,2234 ****
tmp0 = lowpart_subreg (mode, iv0.base, comp_mode);
tmp1 = lowpart_subreg (mode, iv1.base, comp_mode);
! bound = simplify_gen_binary (MINUS, mode, mmin, step);
assumption = simplify_gen_relational (cond, SImode, mode,
bound, tmp0);
desc->assumptions =
--- 2235,2242 ----
tmp0 = lowpart_subreg (mode, iv0.base, comp_mode);
tmp1 = lowpart_subreg (mode, iv1.base, comp_mode);
! bound = simplify_gen_binary (MINUS, mode, mode_mmin,
! lowpart_subreg (mode, step, comp_mode));
assumption = simplify_gen_relational (cond, SImode, mode,
bound, tmp0);
desc->assumptions =
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.362.2.30.2.8
diff -c -3 -p -r1.362.2.30.2.8 rtl.h
*** rtl.h 25 Apr 2004 20:33:37 -0000 1.362.2.30.2.8
--- rtl.h 9 May 2004 15:05:43 -0000
*************** extern bool expensive_function_p (int);
*** 2453,2459 ****
extern void tracer (void);
/* In stor-layout.c. */
! extern void get_mode_bounds (enum machine_mode, int, rtx *, rtx *);
/* In loop-unswitch.c */
extern rtx reversed_condition (rtx);
--- 2453,2460 ----
extern void tracer (void);
/* In stor-layout.c. */
! extern void get_mode_bounds (enum machine_mode, int, enum machine_mode,
! rtx *, rtx *);
/* In loop-unswitch.c */
extern rtx reversed_condition (rtx);
*************** extern void simplify_using_condition (rt
*** 2465,2473 ****
/* In var-tracking.c */
extern void variable_tracking_main (void);
-
- /* In stor-layout.c. */
- extern void get_mode_bounds (enum machine_mode, int, rtx *, rtx *);
/* In loop-unswitch.c */
extern rtx reversed_condition (rtx);
--- 2466,2471 ----
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.126.2.26.2.4
diff -c -3 -p -r1.126.2.26.2.4 stor-layout.c
*** stor-layout.c 25 Apr 2004 20:33:39 -0000 1.126.2.26.2.4
--- stor-layout.c 9 May 2004 15:05:43 -0000
*************** get_best_mode (int bitsize, int bitpos,
*** 2157,2182 ****
}
/* Gets minimal and maximal values for MODE (signed or unsigned depending on
! SIGN). */
void
! get_mode_bounds (enum machine_mode mode, int sign, rtx *mmin, rtx *mmax)
{
! int size = GET_MODE_BITSIZE (mode);
if (size > HOST_BITS_PER_WIDE_INT)
abort ();
if (sign)
{
! *mmin = GEN_INT (-((unsigned HOST_WIDE_INT) 1 << (size - 1)));
! *mmax = GEN_INT (((unsigned HOST_WIDE_INT) 1 << (size - 1)) - 1);
}
else
{
! *mmin = const0_rtx;
! *mmax = GEN_INT (((unsigned HOST_WIDE_INT) 1 << (size - 1) << 1) - 1);
}
}
#include "gt-stor-layout.h"
--- 2157,2188 ----
}
/* Gets minimal and maximal values for MODE (signed or unsigned depending on
! SIGN). The returned constants are made to be usable in TARGET_MODE. */
void
! get_mode_bounds (enum machine_mode mode, int sign,
! enum machine_mode target_mode,
! rtx *mmin, rtx *mmax)
{
! unsigned size = GET_MODE_BITSIZE (mode);
! unsigned HOST_WIDE_INT min_val, max_val;
if (size > HOST_BITS_PER_WIDE_INT)
abort ();
if (sign)
{
! min_val = -((unsigned HOST_WIDE_INT) 1 << (size - 1));
! max_val = ((unsigned HOST_WIDE_INT) 1 << (size - 1)) - 1;
}
else
{
! min_val = 0;
! max_val = ((unsigned HOST_WIDE_INT) 1 << (size - 1) << 1) - 1;
}
+
+ *mmin = GEN_INT (trunc_int_for_mode (min_val, target_mode));
+ *mmax = GEN_INT (trunc_int_for_mode (max_val, target_mode));
}
#include "gt-stor-layout.h"