aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclyon <clyon@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-04 12:43:03 +0000
committerclyon <clyon@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-04 12:43:03 +0000
commit7918f00dd46d9733840dd3cdc9fa1bdde44a2a15 (patch)
tree6a64ff33746994cec344473d028d45ddacab1192
parentd92cd12417bd8e07ac679a4cf212eb5f77d626a3 (diff)
2015-06-02 Christophe Lyon <christophe.lyon@linaro.org>
Backport from trunk r217753. 2014-11-19 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/63843 gcc/ * simplify-rtx.c (simplify_binary_operation_1) <case ASHIFTRT>: For optimization of ashiftrt of subreg of lshiftrt, check that code is ASHIFTRT. gcc/testsuite * gcc.c-torture/execute/pr63843.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/linaro/gcc-4_9-branch@224125 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog.linaro10
-rw-r--r--gcc/simplify-rtx.c73
-rw-r--r--gcc/testsuite/ChangeLog.linaro8
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr63843.c31
4 files changed, 85 insertions, 37 deletions
diff --git a/gcc/ChangeLog.linaro b/gcc/ChangeLog.linaro
index 040fc49afb3..5f6dcda83bf 100644
--- a/gcc/ChangeLog.linaro
+++ b/gcc/ChangeLog.linaro
@@ -1,3 +1,13 @@
+2015-06-02 Christophe Lyon <christophe.lyon@linaro.org>
+
+ Backport from trunk r217753.
+ 2014-11-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/63843
+ * simplify-rtx.c (simplify_binary_operation_1) <case ASHIFTRT>: For
+ optimization of ashiftrt of subreg of lshiftrt, check that code
+ is ASHIFTRT.
+
2015-04-16 Christophe Lyon <christophe.lyon@linaro.org>
* LINARO-VERSION: Bump version.
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 788832355d2..c89311f39ea 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -3349,43 +3349,42 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode,
&& ! side_effects_p (op1))
return op0;
/* Given:
- scalar modes M1, M2
- scalar constants c1, c2
- size (M2) > size (M1)
- c1 == size (M2) - size (M1)
- optimize:
- (ashiftrt:M1 (subreg:M1 (lshiftrt:M2 (reg:M2)
- (const_int <c1>))
- <low_part>)
- (const_int <c2>))
- to:
- (subreg:M1 (ashiftrt:M2 (reg:M2)
- (const_int <c1 + c2>))
- <low_part>). */
- if (!VECTOR_MODE_P (mode)
- && SUBREG_P (op0)
- && CONST_INT_P (op1)
- && (GET_CODE (SUBREG_REG (op0)) == LSHIFTRT)
- && !VECTOR_MODE_P (GET_MODE (SUBREG_REG (op0)))
- && CONST_INT_P (XEXP (SUBREG_REG (op0), 1))
- && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
- > GET_MODE_BITSIZE (mode))
- && (INTVAL (XEXP (SUBREG_REG (op0), 1))
- == (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
- - GET_MODE_BITSIZE (mode)))
- && subreg_lowpart_p (op0))
- {
- rtx tmp = GEN_INT (INTVAL (XEXP (SUBREG_REG (op0), 1))
- + INTVAL (op1));
- machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
- tmp = simplify_gen_binary (ASHIFTRT,
- GET_MODE (SUBREG_REG (op0)),
- XEXP (SUBREG_REG (op0), 0),
- tmp);
- return simplify_gen_subreg (mode, tmp, inner_mode,
- subreg_lowpart_offset (mode,
- inner_mode));
- }
+ scalar modes M1, M2
+ scalar constants c1, c2
+ size (M2) > size (M1)
+ c1 == size (M2) - size (M1)
+ optimize:
+ (ashiftrt:M1 (subreg:M1 (lshiftrt:M2 (reg:M2) (const_int <c1>))
+ <low_part>)
+ (const_int <c2>))
+ to:
+ (subreg:M1 (ashiftrt:M2 (reg:M2) (const_int <c1 + c2>))
+ <low_part>). */
+ if (code == ASHIFTRT
+ && !VECTOR_MODE_P (mode)
+ && SUBREG_P (op0)
+ && CONST_INT_P (op1)
+ && GET_CODE (SUBREG_REG (op0)) == LSHIFTRT
+ && !VECTOR_MODE_P (GET_MODE (SUBREG_REG (op0)))
+ && CONST_INT_P (XEXP (SUBREG_REG (op0), 1))
+ && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
+ > GET_MODE_BITSIZE (mode))
+ && (INTVAL (XEXP (SUBREG_REG (op0), 1))
+ == (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
+ - GET_MODE_BITSIZE (mode)))
+ && subreg_lowpart_p (op0))
+ {
+ rtx tmp = GEN_INT (INTVAL (XEXP (SUBREG_REG (op0), 1))
+ + INTVAL (op1));
+ machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
+ tmp = simplify_gen_binary (ASHIFTRT,
+ GET_MODE (SUBREG_REG (op0)),
+ XEXP (SUBREG_REG (op0), 0),
+ tmp);
+ return simplify_gen_subreg (mode, tmp, inner_mode,
+ subreg_lowpart_offset (mode,
+ inner_mode));
+ }
canonicalize_shift:
if (SHIFT_COUNT_TRUNCATED && CONST_INT_P (op1))
{
diff --git a/gcc/testsuite/ChangeLog.linaro b/gcc/testsuite/ChangeLog.linaro
index 93ebc9c04b4..143ec3f78ff 100644
--- a/gcc/testsuite/ChangeLog.linaro
+++ b/gcc/testsuite/ChangeLog.linaro
@@ -1,3 +1,11 @@
+2015-06-02 Christophe Lyon <christophe.lyon@linaro.org>
+
+ Backport from trunk r217753.
+ 2014-11-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/63843
+ * gcc.c-torture/execute/pr63843.c: New test.
+
2015-04-16 Christophe Lyon <christophe.lyon@linaro.org>
GCC Linaro 4.9-2015.04 snapshot.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr63843.c b/gcc/testsuite/gcc.c-torture/execute/pr63843.c
new file mode 100644
index 00000000000..9f6c7b06c39
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr63843.c
@@ -0,0 +1,31 @@
+/* PR rtl-optimization/63843 */
+
+static inline __attribute__ ((always_inline))
+unsigned short foo (unsigned short v)
+{
+ return (v << 8) | (v >> 8);
+}
+
+unsigned short __attribute__ ((noinline, noclone, hot))
+bar (unsigned char *x)
+{
+ unsigned int a;
+ unsigned short b;
+ __builtin_memcpy (&a, &x[0], sizeof (a));
+ a ^= 0x80808080U;
+ __builtin_memcpy (&x[0], &a, sizeof (a));
+ __builtin_memcpy (&b, &x[2], sizeof (b));
+ return foo (b);
+}
+
+int
+main ()
+{
+ unsigned char x[8] = { 0x01, 0x01, 0x01, 0x01 };
+ if (__CHAR_BIT__ == 8
+ && sizeof (short) == 2
+ && sizeof (int) == 4
+ && bar (x) != 0x8181U)
+ __builtin_abort ();
+ return 0;
+}