diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4007a660c21..0347c24ae88 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-07-08 Adam Nemet + + * simplify-rtx.c (simplify_binary_operation_1) : Transform (and + (truncate)) into (truncate (and)). + 2009-07-08 Adam Nemet * combine.c (make_extraction): Check TRULY_NOOP_TRUNCATION before diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 782d7172091..ff690684ee6 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2336,6 +2336,18 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, return simplify_gen_unary (ZERO_EXTEND, mode, tem, imode); } + /* Transform (and (truncate X) C) into (truncate (and X C)). This way + we might be able to further simplify the AND with X and potentially + remove the truncation altogether. */ + if (GET_CODE (op0) == TRUNCATE && CONST_INT_P (trueop1)) + { + rtx x = XEXP (op0, 0); + enum machine_mode xmode = GET_MODE (x); + tem = simplify_gen_binary (AND, xmode, x, + gen_int_mode (INTVAL (trueop1), xmode)); + return simplify_gen_unary (TRUNCATE, mode, tem, xmode); + } + /* Canonicalize (A | C1) & C2 as (A & C2) | (C1 & C2). */ if (GET_CODE (op0) == IOR && CONST_INT_P (trueop1) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 72585073651..3dcfad3fe3a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,9 +1,13 @@ +2009-07-08 Adam Nemet + + * gcc.target/mips/truncate-5.c: New test. + 2009-07-08 Jerry DeLisle PR libfortran/40330 PR libfortran/40662 * gfortran.dg/fmt_cache_1.f: New test. - + 2009-07-08 Tobias Burnus PR fortran/40675 @@ -24,7 +28,7 @@ * gfortran.dg/proc_ptr_21.f90: New test. 2009-07-08 Manuel López-Ibáñez - + PR c++/31246 * g++.dg/warn/pr31246.C: New. * g++.dg/warn/pr31246-2.C: New. diff --git a/gcc/testsuite/gcc.target/mips/truncate-5.c b/gcc/testsuite/gcc.target/mips/truncate-5.c new file mode 100644 index 00000000000..046ef80c453 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/truncate-5.c @@ -0,0 +1,14 @@ +/* If we AND in DI mode (i.e. replace the order of TRUNCATE and AND) then we + can remove the TRUNCATE. */ +/* { dg-options "-O -mgp64" } */ +/* { dg-final { scan-assembler-not "\tsll\t\[^\n\]*,0" } } */ + +struct s +{ + unsigned a:5; +}; + +f (struct s *s, unsigned long long a) +{ + s->a = a & 0x3; +}