From: Georg-Johann Lay Date: Fri, 8 Feb 2013 13:23:34 +0000 (+0000) Subject: re PR tree-optimization/56064 (Optimize VIEW_CONVERT_EXPR with FIXED_CST) X-Git-Tag: upstream/12.2.0~71337 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff54464986fd1994754f5cbaa3921628818cc63f;p=platform%2Fupstream%2Fgcc.git re PR tree-optimization/56064 (Optimize VIEW_CONVERT_EXPR with FIXED_CST) gcc/ PR tree-optimization/56064 * fixed-value.c (fixed_from_double_int): Sign/zero extend payload bits according to mode. * fixed-value.h (fixed_from_double_int) (const_fixed_from_double_int): Adjust comments. gcc/testsuite/ PR tree-optimization/56064 * gcc.dg/fixed-point/view-convert-2.c: New test. From-SVN: r195885 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d7b0e64..55e90b4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2013-02-08 Georg-Johann Lay + + PR tree-optimization/56064 + * fixed-value.c (fixed_from_double_int): Sign/zero extend payload + bits according to mode. + * fixed-value.h (fixed_from_double_int) + (const_fixed_from_double_int): Adjust comments. + 2013-02-08 Richard Biener PR lto/56231 diff --git a/gcc/fixed-value.c b/gcc/fixed-value.c index 2e97a49..18ce47e 100644 --- a/gcc/fixed-value.c +++ b/gcc/fixed-value.c @@ -83,7 +83,7 @@ check_real_for_fixed_mode (REAL_VALUE_TYPE *real_value, enum machine_mode mode) /* Construct a CONST_FIXED from a bit payload and machine mode MODE. - The bits in PAYLOAD are used verbatim. */ + The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */ FIXED_VALUE_TYPE fixed_from_double_int (double_int payload, enum machine_mode mode) @@ -92,7 +92,13 @@ fixed_from_double_int (double_int payload, enum machine_mode mode) gcc_assert (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_DOUBLE_INT); - value.data = payload; + if (SIGNED_SCALAR_FIXED_POINT_MODE_P (mode)) + value.data = payload.sext (1 + GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode)); + else if (UNSIGNED_SCALAR_FIXED_POINT_MODE_P (mode)) + value.data = payload.zext (GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode)); + else + gcc_unreachable(); + value.mode = mode; return value; diff --git a/gcc/fixed-value.h b/gcc/fixed-value.h index 5ffe67c..f59466a 100644 --- a/gcc/fixed-value.h +++ b/gcc/fixed-value.h @@ -50,12 +50,12 @@ extern FIXED_VALUE_TYPE fconst1[MAX_FCONST1]; extern rtx const_fixed_from_fixed_value (FIXED_VALUE_TYPE, enum machine_mode); /* Construct a FIXED_VALUE from a bit payload and machine mode MODE. - The bits in PAYLOAD are used verbatim. */ + The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */ extern FIXED_VALUE_TYPE fixed_from_double_int (double_int, enum machine_mode); /* Return a CONST_FIXED from a bit payload and machine mode MODE. - The bits in PAYLOAD are used verbatim. */ + The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */ static inline rtx const_fixed_from_double_int (double_int payload, enum machine_mode mode) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1209b94..31f0bf2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-02-08 Georg-Johann Lay + + PR tree-optimization/56064 + * gcc.dg/fixed-point/view-convert-2.c: New test. + 2013-02-08 Michael Matz PR tree-optimization/52448 diff --git a/gcc/testsuite/gcc.dg/fixed-point/view-convert-2.c b/gcc/testsuite/gcc.dg/fixed-point/view-convert-2.c new file mode 100644 index 0000000..fbce518 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fixed-point/view-convert-2.c @@ -0,0 +1,139 @@ +/* PR tree-optimization/56064 */ +/* { dg-do run } */ +/* { dg-options "-std=gnu99 -O2" } */ + +extern void abort (void); +extern void exit (int); + +void test_k (void) +{ + _Accum a; + __INT32_TYPE__ i = -__INT32_MAX__; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&a, &i, sizeof (a)); + + if (a >= 0k) + abort(); +} + +void test_0k (void) +{ + _Accum a; + __INT32_TYPE__ i = 0; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&a, &i, sizeof (a)); + + if (a != 0k) + abort(); +} + + +void test_hr (void) +{ + short _Fract a; + __INT8_TYPE__ i = -__INT8_MAX__; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&a, &i, sizeof (a)); + + if (a >= 0hr) + abort(); +} + +void test_0hr (void) +{ + short _Fract a; + __INT8_TYPE__ i = 0; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&a, &i, sizeof (a)); + + if (a != 0hr) + abort(); +} + + +void test_si (void) +{ + _Accum a = __ACCUM_MIN__; + __INT32_TYPE__ i; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&i, &a, sizeof (i)); + + if (i >= 0) + abort(); +} + +void test_0si (void) +{ + _Accum a = 0; + __INT32_TYPE__ i; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&i, &a, sizeof (i)); + + if (i != 0) + abort(); +} + + +void test_qi (void) +{ + short _Fract a = __SFRACT_MIN__; + __INT8_TYPE__ i; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&i, &a, sizeof (i)); + + if (i >= 0) + abort(); +} + +void test_0qi (void) +{ + short _Fract a = 0hr; + __INT8_TYPE__ i; + + if (sizeof (a) != sizeof (i)) + return; + + __builtin_memcpy (&i, &a, sizeof (i)); + + if (i != 0) + abort(); +} + + +int main (void) +{ + test_hr(); + test_k(); + test_qi(); + test_si(); + + test_0hr(); + test_0k(); + test_0qi(); + test_0si(); + + exit (0); + + return 0; +}