aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/gcc/gcc-4.3.3/debian/pr33148.dpatch
blob: bcf30ffb56ac971748390ad79b9ee21952216a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /bin/sh -e

# DP: Fix (neg (lt X 0)) optimization (PR rtl-optimization/33148)

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0


From: Jakub Jelinek <jakub@redhat.com>
Sender: gcc-patches-owner@gcc.gnu.org
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix (neg (lt X 0)) optimization (PR rtl-optimization/33148)
Date: Mon, 27 Aug 2007 07:22:44 -0400

Hi!

PR25600 change introduced an optimization of (neg (lt x 0)) to
(ashirtrt x C), but it is not checking whether x's mode is suitable
for it.  As it checks that op1 is const0_rtx, I believe MODE_FLOAT
or VECTOR_MODE_P modes are not a problem, CC modes can certainly appear
in LT's first operand with second operand const0_rtx.
So, when we optimize
(neg:DI (lt:DI (reg:CC ...) (const_int 0)))
we create something like
(sign_extend:DI (ashirtrt:CC (reg:CC ...) (const_int 31)))
which is IMHO invalid RTL, ashirtrt is documented on fixed point modes
only (guess vector modes aren't listed just by omission) and so is
sign_extend.

Ok for 4.2/trunk?

2007-08-27  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/33148
	* simplify-rtx.c (simplify_unary_operation_1): Only optimize
	(neg (lt X 0)) if X has scalar int mode.

	* gcc.c-torture/compile/20070827-1.c: New test.

--- gcc/simplify-rtx.c.jj	2007-08-27 10:15:33.000000000 +0200
+++ gcc/simplify-rtx.c	2007-08-27 12:12:51.000000000 +0200
@@ -583,7 +583,8 @@ simplify_unary_operation_1 (enum rtx_cod
       /* (neg (lt x 0)) is (ashiftrt X C) if STORE_FLAG_VALUE is 1.  */
       /* (neg (lt x 0)) is (lshiftrt X C) if STORE_FLAG_VALUE is -1.  */
       if (GET_CODE (op) == LT
-	  && XEXP (op, 1) == const0_rtx)
+	  && XEXP (op, 1) == const0_rtx
+	  && SCALAR_INT_MODE_P (GET_MODE (XEXP (op, 0))))
 	{
 	  enum machine_mode inner = GET_MODE (XEXP (op, 0));
 	  int isize = GET_MODE_BITSIZE (inner);
--- gcc/testsuite/gcc.c-torture/compile/20070827-1.c.jj	2007-08-27 12:17:20.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/compile/20070827-1.c	2007-08-27 12:15:45.000000000 +0200
@@ -0,0 +1,20 @@
+/* PR rtl-optimization/33148 */
+
+int
+foo (unsigned int *p, int *q, unsigned int w, unsigned int b)
+{
+  unsigned int i;
+  int mask;
+
+  if (q[0] < q[1])
+    mask = 0xff;
+  else
+    mask = 0;
+
+  for (i = 0; 8 * i < w; i++)
+    {
+      b ^= mask;
+      *p++ = b;
+    }
+  return 0;
+}

	Jakub