OSDN Git Service

* simplify-rtx.c (simplify_binary_operation_1) <AND>: Transform (and
authornemet <nemet@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Jul 2009 05:43:56 +0000 (05:43 +0000)
committernemet <nemet@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Jul 2009 05:43:56 +0000 (05:43 +0000)
        (truncate)) into (truncate (and)).

testsuite/
* gcc.target/mips/truncate-5.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149402 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/mips/truncate-5.c [new file with mode: 0644]

index 4007a66..0347c24 100644 (file)
@@ -1,5 +1,10 @@
 2009-07-08  Adam Nemet  <anemet@caviumnetworks.com>
 
+       * simplify-rtx.c (simplify_binary_operation_1) <AND>: Transform (and
+        (truncate)) into (truncate (and)).
+
+2009-07-08  Adam Nemet  <anemet@caviumnetworks.com>
+
        * combine.c (make_extraction): Check TRULY_NOOP_TRUNCATION before
        creating LHS paradoxical subregs.  Fix surrounding returns to
        use NULL_RTX rather than 0.
index 782d717..ff69068 100644 (file)
@@ -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)
index 7258507..3dcfad3 100644 (file)
@@ -1,9 +1,13 @@
+2009-07-08  Adam Nemet  <anemet@caviumnetworks.com>
+
+       * gcc.target/mips/truncate-5.c: New test.
+
 2009-07-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/40330
        PR libfortran/40662
        * gfortran.dg/fmt_cache_1.f: New test.
-       
+
 2009-07-08  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/40675
@@ -24,7 +28,7 @@
        * gfortran.dg/proc_ptr_21.f90: New test.
 
 2009-07-08  Manuel López-Ibáñez  <manu@gcc.gnu.org>
-       
+
        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 (file)
index 0000000..046ef80
--- /dev/null
@@ -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;
+}