From dcf8468f1cad977c1f82aa008aecc74f5c858161 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Sat, 1 Sep 2012 18:52:19 +0000 Subject: [PATCH] simplify-rtx.c (simplify_unary_operation_1 ): A truncate of a memory is just loading the low part of the memory. 2012-09-01 Andrew Pinski * simplify-rtx.c (simplify_unary_operation_1 ): A truncate of a memory is just loading the low part of the memory. 2012-09-01 Andrew Pinski * gcc.target/mips/truncate-8.c: New testcase. From-SVN: r190848 --- gcc/ChangeLog | 5 +++++ gcc/simplify-rtx.c | 8 ++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.target/mips/truncate-8.c | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gcc.target/mips/truncate-8.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 14b923c1f3a..45325cb3e9d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-09-01 Andrew Pinski + + * simplify-rtx.c (simplify_unary_operation_1 ): + A truncate of a memory is just loading the low part of the memory. + 2012-09-01 Uros Bizjak PR target/46829 diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index a878048ac97..f59150ee2c1 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -869,6 +869,14 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op) && COMPARISON_P (op) && (STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0) return rtl_hooks.gen_lowpart_no_emit (mode, op); + + /* A truncate of a memory is just loading the low part of the memory + if we are not changing the meaning of the address. */ + if (GET_CODE (op) == MEM + && !MEM_VOLATILE_P (op) + && !mode_dependent_address_p (XEXP (op, 0))) + return rtl_hooks.gen_lowpart_no_emit (mode, op); + break; case FLOAT_TRUNCATE: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5f88b77415..648b014af69 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2012-09-01 Andrew Pinski + + * gcc.target/mips/truncate-8.c: New testcase. + 2012-09-01 Uros Bizjak PR target/46829 diff --git a/gcc/testsuite/gcc.target/mips/truncate-8.c b/gcc/testsuite/gcc.target/mips/truncate-8.c new file mode 100644 index 00000000000..f172b2223fd --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/truncate-8.c @@ -0,0 +1,18 @@ +/* { dg-options "-mgp64" } */ +/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\tlw\t" } } */ +/* { dg-final { scan-assembler-not "\tsll\t" } } */ +/* { dg-final { scan-assembler-not "\tld\t" } } */ + +struct s +{ + long long a; + int b; +}; + +int +foo (struct s *x) +{ + return x->a; +} + -- 2.30.2