re PR rtl-optimization/34522 (inefficient code for long long multiply when only low...
authorPaolo Bonzini <bonzini@gnu.org>
Wed, 12 Mar 2008 15:33:45 +0000 (15:33 +0000)
committerPaolo Bonzini <bonzini@gcc.gnu.org>
Wed, 12 Mar 2008 15:33:45 +0000 (15:33 +0000)
2008-03-12  Paolo Bonzini  <bonzini@gnu.org>

PR tree-opt/35422
* fold-const.c (fold_unary) <NOP_EXPR>: Distribute a narrowing
conversion to the operands of a multiplication.

testsuite:
2008-03-12  Paolo Bonzini  <bonzini@gnu.org>

PR tree-opt/35422
* gcc.dg/vect/slp-7.c: Change target keywords required for vectorizing
third loop.
* gcc.target/i386/pr35422.c: New.

From-SVN: r133144

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/slp-7.c
gcc/testsuite/gcc.target/i386/pr34522.c [new file with mode: 0644]

index 480160854f107c96db16cced64801bab019ab064..dfdbfc26a198d61cd0db2716c45751499ea34cfe 100644 (file)
@@ -1,3 +1,9 @@
+2008-03-12  Paolo Bonzini  <bonzini@gnu.org>
+
+       PR tree-opt/35422
+       * fold-const.c (fold_unary) <NOP_EXPR>: Distribute a narrowing
+       conversion to the operands of a multiplication.
+
 2008-03-12  Richard Guenther  <rguenther@suse.de>
 
        * Makefile.in (OBJS-common): Add tree-ssa-phiprop.o
index 4774661c4e32a95060fcf12815f6dd6830900246..7cf132b21799e9fa37be7f5d36a8dd723a41ad7c 100644 (file)
@@ -7926,6 +7926,26 @@ fold_unary (enum tree_code code, tree type, tree op0)
            return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem));
        }
 
+      /* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the
+        type of X and Y (integer types only).  */
+      if (INTEGRAL_TYPE_P (type)
+         && TREE_CODE (op0) == MULT_EXPR
+         && INTEGRAL_TYPE_P (TREE_TYPE (op0))
+         && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (op0)))
+       {
+         /* Be careful not to introduce new overflows.  */
+         tree mult_type;
+          if (TYPE_OVERFLOW_WRAPS (type))
+           mult_type = type;
+         else
+           mult_type = unsigned_type_for (type);
+         
+         tem = fold_build2 (MULT_EXPR, mult_type,
+                            fold_convert (mult_type, TREE_OPERAND (op0, 0)),
+                            fold_convert (mult_type, TREE_OPERAND (op0, 1)));
+         return fold_convert (type, tem);
+       }
+
       tem = fold_convert_const (code, type, op0);
       return tem ? tem : NULL_TREE;
 
index 52a96c338226aaef8beb6fde7a2125b74f80fdbb..a313f021e2174eaf67e0b1156144f9006b0a3faa 100644 (file)
@@ -1,3 +1,10 @@
+2008-03-12  Paolo Bonzini  <bonzini@gnu.org>
+
+       PR tree-opt/35422
+       * gcc.dg/vect/slp-7.c: Change target keywords required for vectorizing
+       third loop.
+       * gcc.target/i386/pr35422.c: New.
+
 2008-03-11  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR tree-opt/35403
index 4ee7029af0ecedfbe0379148fc7c8615c0f69c2b..f000fc9059fb452c4d5d901f7059ae6238e6a95c 100644 (file)
@@ -120,8 +120,9 @@ int main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "vectorized 3 loops" 1 "vect"  {target {  vect_strided &&  vect_int_mult  } } } }*/
-/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect"  {target  { ! {  vect_strided && vect_int_mult } } } } } */
-/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect"  } } */
+/* { dg-final { scan-tree-dump-times "vectorized 3 loops" 1 "vect"  { target { vect_unpack && vect_int_mult } } } }*/
+/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect"  { target { ! { vect_unpack && vect_int_mult } } } } }*/
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 3 "vect"  { target { vect_unpack && vect_int_mult } } } } */
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect"  { target { ! { vect_unpack && vect_int_mult } } } } } */
 /* { dg-final { cleanup-tree-dump "vect" } } */
  
diff --git a/gcc/testsuite/gcc.target/i386/pr34522.c b/gcc/testsuite/gcc.target/i386/pr34522.c
new file mode 100644 (file)
index 0000000..d5e66ae
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-O2" } */
+/* { dg-do compile } */
+/* { dg-require-effective-target ilp32 } */
+
+int test(long long a, long long b)
+{
+        return a * b;
+}
+
+/* Check that we did not spill anything.  This is all that is needed
+   to qualify the generated code as "decent"...  */
+
+/* { dg-final { scan-assembler-not "%e[sd]i" } } */