Refactor gimple_fold_builtin_memory_op function.
authorMartin Liska <mliska@suse.cz>
Tue, 30 Apr 2019 09:19:41 +0000 (11:19 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 30 Apr 2019 09:19:41 +0000 (09:19 +0000)
2019-04-30  Martin Liska  <mliska@suse.cz>

* gimple-fold.c (gimple_fold_builtin_memory_op): Change endp
into built_in_function enum. Remove code for endp == 2 and
use BUILT_IN_* constants.
(gimple_fold_builtin): Call the function with fcode.

From-SVN: r270682

gcc/ChangeLog
gcc/gimple-fold.c

index e053ff1c102378513afed6ec035af24e8437bcaf..cb69c4d0841c2fd7bb3c5fbd4aabcc8d2221c704 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-30  Martin Liska  <mliska@suse.cz>
+
+       * gimple-fold.c (gimple_fold_builtin_memory_op): Change endp
+       into built_in_function enum. Remove code for endp == 2 and
+       use BUILT_IN_* constants.
+       (gimple_fold_builtin): Call the function with fcode.
+
 2019-04-30  Martin Liska  <mliska@suse.cz>
 
        * config/i386/i386.c (ix86_builtin_reciprocal): Cast
index f30818042ee24531b82eb38d23fd4b1eba431d2c..d3ef05b52433c5065be815ebced880e2f3129657 100644 (file)
@@ -692,7 +692,7 @@ size_must_be_zero_p (tree size)
 
 static bool
 gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
-                              tree dest, tree src, int endp)
+                              tree dest, tree src, enum built_in_function code)
 {
   gimple *stmt = gsi_stmt (*gsi);
   tree lhs = gimple_call_lhs (stmt);
@@ -839,7 +839,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
            }
        }
 
-      if (endp == 3)
+      if (code == BUILT_IN_MEMMOVE)
        {
          /* Both DEST and SRC must be pointer types.
             ??? This is what old code did.  Is the testing for pointer types
@@ -1102,17 +1102,16 @@ set_vop_and_replace:
 
 done:
   gimple_seq stmts = NULL;
-  if (endp == 0 || endp == 3)
+  if (code == BUILT_IN_MEMCPY || code == BUILT_IN_MEMMOVE)
     len = NULL_TREE;
-  else if (endp == 2)
-    len = gimple_build (&stmts, loc, MINUS_EXPR, TREE_TYPE (len), len,
-                       ssize_int (1));
-  if (endp == 2 || endp == 1)
+  else if (code == BUILT_IN_MEMPCPY)
     {
       len = gimple_convert_to_ptrofftype (&stmts, loc, len);
       dest = gimple_build (&stmts, loc, POINTER_PLUS_EXPR,
                           TREE_TYPE (dest), dest, len);
     }
+  else
+    gcc_unreachable ();
 
   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   gimple *repl = gimple_build_assign (lhs, dest);
@@ -3847,14 +3846,10 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi)
                                         gimple_call_arg (stmt, 1),
                                         gimple_call_arg (stmt, 2));
     case BUILT_IN_MEMCPY:
-      return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
-                                           gimple_call_arg (stmt, 1), 0);
     case BUILT_IN_MEMPCPY:
-      return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
-                                           gimple_call_arg (stmt, 1), 1);
     case BUILT_IN_MEMMOVE:
       return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
-                                           gimple_call_arg (stmt, 1), 3);
+                                           gimple_call_arg (stmt, 1), fcode);
     case BUILT_IN_SPRINTF_CHK:
     case BUILT_IN_VSPRINTF_CHK:
       return gimple_fold_builtin_sprintf_chk (gsi, fcode);