aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2004-07-15 02:09:00 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2004-07-15 02:09:00 +0200
commitb8b139c7421e29b5a103ef09d960a375a6dff3bd (patch)
tree78c132b5b29ebc1362f28bd7a6454e0d1cb0d045 /gcc
parentaa3c6dc1604edf2119da7cf6d39c6afab3a676d7 (diff)
downloadgcc-b8b139c7421e29b5a103ef09d960a375a6dff3bd.zip
gcc-b8b139c7421e29b5a103ef09d960a375a6dff3bd.tar.gz
gcc-b8b139c7421e29b5a103ef09d960a375a6dff3bd.tar.bz2
expr.c (expand_assignment): Reenable bitfield += optimizations.
* expr.c (expand_assignment): Reenable bitfield += optimizations. Use alias set 0 for memory, do proper mode calculations and adjust address for memories. * gcc.c-torture/execute/20040709-1.c: New test. * gcc.c-torture/execute/20040709-2.c: New test. From-SVN: r84722
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/expr.c82
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20040709-1.c147
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20040709-2.c153
5 files changed, 372 insertions, 21 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cb26f13..675e22b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2004-07-15 Jakub Jelinek <jakub@redhat.com>
+
+ * expr.c (expand_assignment): Reenable bitfield += optimizations.
+ Use alias set 0 for memory, do proper mode calculations and adjust
+ address for memories.
+
2004-07-14 Per Bothner <per@bothner.com>
* input.h: If USE_MAPPED_LOCATION, define separate expanded_location
diff --git a/gcc/expr.c b/gcc/expr.c
index 95dbf35..302c4ee 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -3528,18 +3528,16 @@ expand_assignment (tree to, tree from, int want_value)
MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
}
- /* Disabled temporarily. GET_MODE (to_rtx) is often not the right
- mode. */
- while (0 && mode1 == VOIDmode && !want_value
- && bitpos + bitsize <= BITS_PER_WORD
- && bitsize < BITS_PER_WORD
+ /* Optimize bitfld op= val in certain cases. */
+ while (mode1 == VOIDmode && !want_value
+ && bitsize > 0 && bitsize < BITS_PER_WORD
&& GET_MODE_BITSIZE (GET_MODE (to_rtx)) <= BITS_PER_WORD
&& !TREE_SIDE_EFFECTS (to)
&& !TREE_THIS_VOLATILE (to))
{
tree src, op0, op1;
- rtx value;
- HOST_WIDE_INT count = bitpos;
+ rtx value, str_rtx = to_rtx;
+ HOST_WIDE_INT bitpos1 = bitpos;
optab binop;
src = from;
@@ -3555,45 +3553,87 @@ expand_assignment (tree to, tree from, int want_value)
if (! operand_equal_p (to, op0, 0))
break;
+ if (MEM_P (str_rtx))
+ {
+ enum machine_mode mode = GET_MODE (str_rtx);
+ HOST_WIDE_INT offset1;
+
+ if (GET_MODE_BITSIZE (mode) == 0
+ || GET_MODE_BITSIZE (mode) > BITS_PER_WORD)
+ mode = word_mode;
+ mode = get_best_mode (bitsize, bitpos1, MEM_ALIGN (str_rtx),
+ mode, 0);
+ if (mode == VOIDmode)
+ break;
+
+ offset1 = bitpos1;
+ bitpos1 %= GET_MODE_BITSIZE (mode);
+ offset1 = (offset1 - bitpos1) / BITS_PER_UNIT;
+ str_rtx = adjust_address (str_rtx, mode, offset1);
+ }
+ else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
+ break;
+
+ /* If the bit field covers the whole REG/MEM, store_field
+ will likely generate better code. */
+ if (bitsize >= GET_MODE_BITSIZE (GET_MODE (str_rtx)))
+ break;
+
+ /* We can't handle fields split accross multiple entities. */
+ if (bitpos1 + bitsize > GET_MODE_BITSIZE (GET_MODE (str_rtx)))
+ break;
+
if (BYTES_BIG_ENDIAN)
- count = GET_MODE_BITSIZE (GET_MODE (to_rtx)) - bitpos - bitsize;
+ bitpos1 = GET_MODE_BITSIZE (GET_MODE (str_rtx)) - bitpos1
+ - bitsize;
/* Special case some bitfield op= exp. */
switch (TREE_CODE (src))
{
case PLUS_EXPR:
case MINUS_EXPR:
- if (count <= 0)
- break;
-
/* For now, just optimize the case of the topmost bitfield
where we don't need to do any masking and also
1 bit bitfields where xor can be used.
We might win by one instruction for the other bitfields
too if insv/extv instructions aren't used, so that
can be added later. */
- if (count + bitsize != GET_MODE_BITSIZE (GET_MODE (to_rtx))
+ if (bitpos1 + bitsize != GET_MODE_BITSIZE (GET_MODE (str_rtx))
&& (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
break;
- value = expand_expr (op1, NULL_RTX, VOIDmode, 0);
+ value = expand_expr (op1, NULL_RTX, GET_MODE (str_rtx), 0);
+ value = convert_modes (GET_MODE (str_rtx),
+ TYPE_MODE (TREE_TYPE (op1)), value,
+ TYPE_UNSIGNED (TREE_TYPE (op1)));
+
+ /* We may be accessing data outside the field, which means
+ we can alias adjacent data. */
+ if (MEM_P (str_rtx))
+ {
+ str_rtx = shallow_copy_rtx (str_rtx);
+ set_mem_alias_set (str_rtx, 0);
+ set_mem_expr (str_rtx, 0);
+ }
+
binop = TREE_CODE (src) == PLUS_EXPR ? add_optab : sub_optab;
if (bitsize == 1
- && count + bitsize != GET_MODE_BITSIZE (GET_MODE (to_rtx)))
+ && bitpos1 + bitsize != GET_MODE_BITSIZE (GET_MODE (str_rtx)))
{
- value = expand_and (GET_MODE (to_rtx), value, const1_rtx,
+ value = expand_and (GET_MODE (str_rtx), value, const1_rtx,
NULL_RTX);
binop = xor_optab;
}
- value = expand_shift (LSHIFT_EXPR, GET_MODE (to_rtx),
- value, build_int_2 (count, 0),
+ value = expand_shift (LSHIFT_EXPR, GET_MODE (str_rtx),
+ value, build_int_2 (bitpos1, 0),
NULL_RTX, 1);
- result = expand_binop (GET_MODE (to_rtx), binop, to_rtx,
- value, to_rtx, 1, OPTAB_WIDEN);
- if (result != to_rtx)
- emit_move_insn (to_rtx, result);
+ result = expand_binop (GET_MODE (str_rtx), binop, str_rtx,
+ value, str_rtx, 1, OPTAB_WIDEN);
+ if (result != str_rtx)
+ emit_move_insn (str_rtx, result);
free_temp_slots ();
pop_temp_slots ();
return NULL_RTX;
+
default:
break;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2503543..caec9d2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-07-15 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.c-torture/execute/20040709-1.c: New test.
+ * gcc.c-torture/execute/20040709-2.c: New test.
+
2004-07-14 Mike Stump <mrs@apple.com>
* gcc.dg/wint_t-1.c: Expect to pass on darwin 10.3.x and later.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20040709-1.c b/gcc/testsuite/gcc.c-torture/execute/20040709-1.c
new file mode 100644
index 0000000..455313a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20040709-1.c
@@ -0,0 +1,147 @@
+/* Test arithmetics on bitfields. */
+
+extern void abort (void);
+extern void exit (int);
+
+unsigned int
+myrnd (void)
+{
+ static unsigned int s = 1388815473;
+ s *= 1103515245;
+ s += 12345;
+ return (s / 65536) % 2048;
+}
+
+#define T(S) \
+struct S s##S; \
+struct S retme##S (struct S x) \
+{ \
+ return x; \
+} \
+ \
+unsigned int fn1##S (unsigned int x) \
+{ \
+ struct S y = s##S; \
+ y.k += x; \
+ y = retme##S (y); \
+ return y.k; \
+} \
+ \
+unsigned int fn2##S (unsigned int x) \
+{ \
+ struct S y = s##S; \
+ y.k += x; \
+ y.k %= 15; \
+ return y.k; \
+} \
+ \
+unsigned int retit##S (void) \
+{ \
+ return s##S.k; \
+} \
+ \
+unsigned int fn3##S (unsigned int x) \
+{ \
+ s##S.k += x; \
+ return retit##S (); \
+} \
+ \
+void test##S (void) \
+{ \
+ int i; \
+ unsigned int mask, v, a, r; \
+ struct S x; \
+ char *p = (char *) &s##S; \
+ for (i = 0; i < sizeof (s##S); ++i) \
+ *p++ = myrnd (); \
+ if (__builtin_classify_type (s##S.l) == 8) \
+ s##S.l = 5.25; \
+ s##S.k = -1; \
+ mask = s##S.k; \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn1##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || x.k != s##S.k || x.l != s##S.l \
+ || ((v + a) & mask) != r) \
+ abort (); \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn2##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || x.k != s##S.k || x.l != s##S.l \
+ || ((((v + a) & mask) % 15) & mask) != r) \
+ abort (); \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn3##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || s##S.k != r || x.l != s##S.l \
+ || ((v + a) & mask) != r) \
+ abort (); \
+}
+
+struct A { unsigned int i : 6, l : 1, j : 10, k : 15; }; T(A)
+struct B { unsigned int i : 6, j : 11, k : 15; unsigned int l; }; T(B)
+struct C { unsigned int l; unsigned int i : 6, j : 11, k : 15; }; T(C)
+struct D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
+struct E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
+struct F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
+struct G { unsigned int i : 12, j : 13, k : 7; unsigned long long l; }; T(G)
+struct H { unsigned int i : 12, j : 11, k : 9; unsigned long long l; }; T(H)
+struct I { unsigned short i : 1, j : 6, k : 9; unsigned long long l; }; T(I)
+struct J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
+struct K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
+struct L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
+struct M { unsigned int l; unsigned int k : 6, j : 11, i : 15; }; T(M)
+struct N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
+struct O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
+struct P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
+struct Q { unsigned int k : 12, j : 13, i : 7; unsigned long long l; }; T(Q)
+struct R { unsigned int k : 12, j : 11, i : 9; unsigned long long l; }; T(R)
+struct S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
+struct T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
+struct U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
+struct V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
+struct W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
+struct X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
+struct Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
+struct Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
+
+int
+main (void)
+{
+ testA ();
+ testB ();
+ testC ();
+ testD ();
+ testE ();
+ testF ();
+ testG ();
+ testH ();
+ testI ();
+ testJ ();
+ testK ();
+ testL ();
+ testM ();
+ testN ();
+ testO ();
+ testP ();
+ testQ ();
+ testR ();
+ testS ();
+ testT ();
+ testU ();
+ testV ();
+ testW ();
+ testX ();
+ testY ();
+ testZ ();
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/20040709-2.c b/gcc/testsuite/gcc.c-torture/execute/20040709-2.c
new file mode 100644
index 0000000..f06811c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20040709-2.c
@@ -0,0 +1,153 @@
+/* Test arithmetics on bitfields. */
+
+extern void abort (void);
+extern void exit (int);
+
+unsigned int
+myrnd (void)
+{
+ static unsigned int s = 1388815473;
+ s *= 1103515245;
+ s += 12345;
+ return (s / 65536) % 2048;
+}
+
+#define T(S) \
+struct S s##S; \
+struct S retme##S (struct S x) \
+{ \
+ return x; \
+} \
+ \
+unsigned int fn1##S (unsigned int x) \
+{ \
+ struct S y = s##S; \
+ y.k += x; \
+ y = retme##S (y); \
+ return y.k; \
+} \
+ \
+unsigned int fn2##S (unsigned int x) \
+{ \
+ struct S y = s##S; \
+ y.k += x; \
+ y.k %= 15; \
+ return y.k; \
+} \
+ \
+unsigned int retit##S (void) \
+{ \
+ return s##S.k; \
+} \
+ \
+unsigned int fn3##S (unsigned int x) \
+{ \
+ s##S.k += x; \
+ return retit##S (); \
+} \
+ \
+void test##S (void) \
+{ \
+ int i; \
+ unsigned int mask, v, a, r; \
+ struct S x; \
+ char *p = (char *) &s##S; \
+ for (i = 0; i < sizeof (s##S); ++i) \
+ *p++ = myrnd (); \
+ if (__builtin_classify_type (s##S.l) == 8) \
+ s##S.l = 5.25; \
+ s##S.k = -1; \
+ mask = s##S.k; \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn1##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || x.k != s##S.k || x.l != s##S.l \
+ || ((v + a) & mask) != r) \
+ abort (); \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn2##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || x.k != s##S.k || x.l != s##S.l \
+ || ((((v + a) & mask) % 15) & mask) != r) \
+ abort (); \
+ v = myrnd (); \
+ a = myrnd (); \
+ s##S.k = v; \
+ x = s##S; \
+ r = fn3##S (a); \
+ if (x.i != s##S.i || x.j != s##S.j \
+ || s##S.k != r || x.l != s##S.l \
+ || ((v + a) & mask) != r) \
+ abort (); \
+}
+
+#ifdef __powerpc64__
+/* Temporary hack for broken PPC64 unaligned handling PR rtl-optimization/13674 */
+# define pck
+#else
+# define pck __attribute__((packed))
+#endif
+struct pck A { unsigned short i : 1, l : 1, j : 3, k : 11; }; T(A)
+struct pck B { unsigned short i : 4, j : 1, k : 11; unsigned int l; }; T(B)
+struct pck C { unsigned int l; unsigned short i : 4, j : 1, k : 11; }; T(C)
+struct pck D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
+struct pck E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
+struct pck F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
+struct pck G { unsigned short i : 1, j : 1, k : 6; unsigned long long l; }; T(G)
+struct pck H { unsigned short i : 6, j : 2, k : 8; unsigned long long l; }; T(H)
+struct pck I { unsigned short i : 1, j : 6, k : 1; unsigned long long l; }; T(I)
+struct pck J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
+struct pck K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
+struct pck L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
+struct pck M { unsigned int l; unsigned short k : 6, j : 11, i : 15; }; T(M)
+struct pck N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
+struct pck O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
+struct pck P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
+struct pck Q { unsigned short k : 12, j : 1, i : 3; unsigned long long l; }; T(Q)
+struct pck R { unsigned short k : 2, j : 11, i : 3; unsigned long long l; }; T(R)
+struct pck S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
+struct pck T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
+struct pck U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
+struct pck V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
+struct pck W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
+struct pck X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
+struct pck Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
+struct pck Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
+
+int
+main (void)
+{
+ testA ();
+ testB ();
+ testC ();
+ testD ();
+ testE ();
+ testF ();
+ testG ();
+ testH ();
+ testI ();
+ testJ ();
+ testK ();
+ testL ();
+ testM ();
+ testN ();
+ testO ();
+ testP ();
+ testQ ();
+ testR ();
+ testS ();
+ testT ();
+ testU ();
+ testV ();
+ testW ();
+ testX ();
+ testY ();
+ testZ ();
+ exit (0);
+}