This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR middle-end/37669
Jakub Jelinek writes:
> See my comment in bugzilla, I think this is an overkill, we should just
> remove the loop which might have been useful when we had to iterate through
> the arguments, but isn't any longer. The only values of arg_mask are
> 1, 2 and 4 and val array has 3 elements anyway, so if you want to keep the
> loop, you could at least use i < nargs && i < 3, which is cheaper than
> floor_log2.
Here is an untested version of the patch without the loop. I can give it a
round of testing if you like this better.
Adam
Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c (revision 141180)
+++ tree-ssa-ccp.c (working copy)
@@ -2430,7 +2430,7 @@ ccp_fold_builtin (gimple stmt)
{
tree result, val[3];
tree callee, a;
- int arg_mask, i, type;
+ int len_arg, type;
bitmap visited;
bool ignore;
int nargs;
@@ -2466,12 +2466,12 @@ ccp_fold_builtin (gimple stmt)
case BUILT_IN_STRLEN:
case BUILT_IN_FPUTS:
case BUILT_IN_FPUTS_UNLOCKED:
- arg_mask = 1;
+ len_arg = 0;
type = 0;
break;
case BUILT_IN_STRCPY:
case BUILT_IN_STRNCPY:
- arg_mask = 2;
+ len_arg = 1;
type = 0;
break;
case BUILT_IN_MEMCPY_CHK:
@@ -2479,17 +2479,17 @@ ccp_fold_builtin (gimple stmt)
case BUILT_IN_MEMMOVE_CHK:
case BUILT_IN_MEMSET_CHK:
case BUILT_IN_STRNCPY_CHK:
- arg_mask = 4;
+ len_arg = 2;
type = 2;
break;
case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STPCPY_CHK:
- arg_mask = 2;
+ len_arg = 1;
type = 1;
break;
case BUILT_IN_SNPRINTF_CHK:
case BUILT_IN_VSNPRINTF_CHK:
- arg_mask = 2;
+ len_arg = 1;
type = 2;
break;
default:
@@ -2498,18 +2498,12 @@ ccp_fold_builtin (gimple stmt)
/* Try to use the dataflow information gathered by the CCP process. */
visited = BITMAP_ALLOC (NULL);
+ bitmap_clear (visited);
memset (val, 0, sizeof (val));
- for (i = 0; i < nargs; i++)
- {
- if ((arg_mask >> i) & 1)
- {
- a = gimple_call_arg (stmt, i);
- bitmap_clear (visited);
- if (!get_maxval_strlen (a, &val[i], visited, type))
- val[i] = NULL_TREE;
- }
- }
+ a = gimple_call_arg (stmt, len_arg);
+ if (!get_maxval_strlen (a, &val[len_arg], visited, type))
+ val[len_arg] = NULL_TREE;
BITMAP_FREE (visited);