Commit 7f9f48be by Richard Sandiford Committed by Richard Sandiford

builtins.c (expand_cmpstrn): Rename to...

gcc/
	* builtins.c (expand_cmpstrn): Rename to...
	(expand_cmpstrn_or_cmpmem): ...this.
	(expand_builtin_strcmp, expand_builtin_strncmp): Update accordingly.
	(expand_builtin_memcmp): Use optabs instead of HAVE_cmpmem/gen_cmpmem.
	Remove mode argument.
	(expand_builtin): Update accordingly.

From-SVN: r227141
parent a666df60
2015-08-24 Richard Sandiford <richard.sandiford@arm.com> 2015-08-24 Richard Sandiford <richard.sandiford@arm.com>
* builtins.c (expand_cmpstrn): Rename to...
(expand_cmpstrn_or_cmpmem): ...this.
(expand_builtin_strcmp, expand_builtin_strncmp): Update accordingly.
(expand_builtin_memcmp): Use optabs instead of HAVE_cmpmem/gen_cmpmem.
Remove mode argument.
(expand_builtin): Update accordingly.
2015-08-24 Richard Sandiford <richard.sandiford@arm.com>
* builtins.c (expand_cmpstr, expand_cmpstrn): New functions. * builtins.c (expand_cmpstr, expand_cmpstrn): New functions.
(expand_builtin_strcmp, expand_builtin_strncmp): Use them. Remove (expand_builtin_strcmp, expand_builtin_strncmp): Use them. Remove
references to HAVE_cmpstr{,n}si and CODE_FOR_cmpstr{,n}si. references to HAVE_cmpstr{,n}si and CODE_FOR_cmpstr{,n}si.
......
...@@ -119,7 +119,6 @@ static rtx expand_builtin_next_arg (void); ...@@ -119,7 +119,6 @@ static rtx expand_builtin_next_arg (void);
static rtx expand_builtin_va_start (tree); static rtx expand_builtin_va_start (tree);
static rtx expand_builtin_va_end (tree); static rtx expand_builtin_va_end (tree);
static rtx expand_builtin_va_copy (tree); static rtx expand_builtin_va_copy (tree);
static rtx expand_builtin_memcmp (tree, rtx, machine_mode);
static rtx expand_builtin_strcmp (tree, rtx); static rtx expand_builtin_strcmp (tree, rtx);
static rtx expand_builtin_strncmp (tree, rtx, machine_mode); static rtx expand_builtin_strncmp (tree, rtx, machine_mode);
static rtx builtin_memcpy_read_str (void *, HOST_WIDE_INT, machine_mode); static rtx builtin_memcpy_read_str (void *, HOST_WIDE_INT, machine_mode);
...@@ -3939,13 +3938,14 @@ expand_cmpstr (insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx, ...@@ -3939,13 +3938,14 @@ expand_cmpstr (insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx,
return NULL_RTX; return NULL_RTX;
} }
/* Try to expand cmpstrn operation ICODE with the given operands. /* Try to expand cmpstrn or cmpmem operation ICODE with the given operands.
ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success, ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success,
otherwise return null. */ otherwise return null. */
static rtx static rtx
expand_cmpstrn (insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx, expand_cmpstrn_or_cmpmem (insn_code icode, rtx target, rtx arg1_rtx,
tree arg3_type, rtx arg3_rtx, HOST_WIDE_INT align) rtx arg2_rtx, tree arg3_type, rtx arg3_rtx,
HOST_WIDE_INT align)
{ {
machine_mode insn_mode = insn_data[icode].operand[0].mode; machine_mode insn_mode = insn_data[icode].operand[0].mode;
...@@ -3966,15 +3966,11 @@ expand_cmpstrn (insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx, ...@@ -3966,15 +3966,11 @@ expand_cmpstrn (insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx,
/* Expand expression EXP, which is a call to the memcmp built-in function. /* Expand expression EXP, which is a call to the memcmp built-in function.
Return NULL_RTX if we failed and the caller should emit a normal call, Return NULL_RTX if we failed and the caller should emit a normal call,
otherwise try to get the result in TARGET, if convenient (and in mode otherwise try to get the result in TARGET, if convenient. */
MODE, if that's convenient). */
static rtx static rtx
expand_builtin_memcmp (tree exp, ATTRIBUTE_UNUSED rtx target, expand_builtin_memcmp (tree exp, rtx target)
ATTRIBUTE_UNUSED machine_mode mode)
{ {
location_t loc ATTRIBUTE_UNUSED = EXPR_LOCATION (exp);
if (!validate_arglist (exp, if (!validate_arglist (exp,
POINTER_TYPE, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE)) POINTER_TYPE, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
return NULL_RTX; return NULL_RTX;
...@@ -3982,78 +3978,66 @@ expand_builtin_memcmp (tree exp, ATTRIBUTE_UNUSED rtx target, ...@@ -3982,78 +3978,66 @@ expand_builtin_memcmp (tree exp, ATTRIBUTE_UNUSED rtx target,
/* Note: The cmpstrnsi pattern, if it exists, is not suitable for /* Note: The cmpstrnsi pattern, if it exists, is not suitable for
implementing memcmp because it will stop if it encounters two implementing memcmp because it will stop if it encounters two
zero bytes. */ zero bytes. */
#if defined HAVE_cmpmemsi insn_code icode = direct_optab_handler (cmpmem_optab, SImode);
{ if (icode == CODE_FOR_nothing)
rtx arg1_rtx, arg2_rtx, arg3_rtx; return NULL_RTX;
rtx result;
rtx insn;
tree arg1 = CALL_EXPR_ARG (exp, 0);
tree arg2 = CALL_EXPR_ARG (exp, 1);
tree len = CALL_EXPR_ARG (exp, 2);
unsigned int arg1_align = get_pointer_alignment (arg1) / BITS_PER_UNIT; tree arg1 = CALL_EXPR_ARG (exp, 0);
unsigned int arg2_align = get_pointer_alignment (arg2) / BITS_PER_UNIT; tree arg2 = CALL_EXPR_ARG (exp, 1);
machine_mode insn_mode; tree len = CALL_EXPR_ARG (exp, 2);
if (HAVE_cmpmemsi) unsigned int arg1_align = get_pointer_alignment (arg1) / BITS_PER_UNIT;
insn_mode = insn_data[(int) CODE_FOR_cmpmemsi].operand[0].mode; unsigned int arg2_align = get_pointer_alignment (arg2) / BITS_PER_UNIT;
else
return NULL_RTX;
/* If we don't have POINTER_TYPE, call the function. */ /* If we don't have POINTER_TYPE, call the function. */
if (arg1_align == 0 || arg2_align == 0) if (arg1_align == 0 || arg2_align == 0)
return NULL_RTX; return NULL_RTX;
/* Make a place to write the result of the instruction. */ machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
result = target; location_t loc = EXPR_LOCATION (exp);
if (! (result != 0 rtx arg1_rtx = get_memory_rtx (arg1, len);
&& REG_P (result) && GET_MODE (result) == insn_mode rtx arg2_rtx = get_memory_rtx (arg2, len);
&& REGNO (result) >= FIRST_PSEUDO_REGISTER)) rtx arg3_rtx = expand_normal (fold_convert_loc (loc, sizetype, len));
result = gen_reg_rtx (insn_mode);
arg1_rtx = get_memory_rtx (arg1, len); /* Set MEM_SIZE as appropriate. */
arg2_rtx = get_memory_rtx (arg2, len); if (CONST_INT_P (arg3_rtx))
arg3_rtx = expand_normal (fold_convert_loc (loc, sizetype, len)); {
set_mem_size (arg1_rtx, INTVAL (arg3_rtx));
set_mem_size (arg2_rtx, INTVAL (arg3_rtx));
}
/* Set MEM_SIZE as appropriate. */ rtx result = expand_cmpstrn_or_cmpmem (icode, target, arg1_rtx, arg2_rtx,
if (CONST_INT_P (arg3_rtx)) TREE_TYPE (len), arg3_rtx,
{ MIN (arg1_align, arg2_align));
set_mem_size (arg1_rtx, INTVAL (arg3_rtx)); if (result)
set_mem_size (arg2_rtx, INTVAL (arg3_rtx)); {
} /* Return the value in the proper mode for this function. */
if (GET_MODE (result) == mode)
return result;
if (HAVE_cmpmemsi) if (target != 0)
insn = gen_cmpmemsi (result, arg1_rtx, arg2_rtx, arg3_rtx, {
GEN_INT (MIN (arg1_align, arg2_align))); convert_move (target, result, 0);
else return target;
gcc_unreachable (); }
if (insn)
emit_insn (insn);
else
emit_library_call_value (memcmp_libfunc, result, LCT_PURE,
TYPE_MODE (integer_type_node), 3,
XEXP (arg1_rtx, 0), Pmode,
XEXP (arg2_rtx, 0), Pmode,
convert_to_mode (TYPE_MODE (sizetype), arg3_rtx,
TYPE_UNSIGNED (sizetype)),
TYPE_MODE (sizetype));
/* Return the value in the proper mode for this function. */
mode = TYPE_MODE (TREE_TYPE (exp));
if (GET_MODE (result) == mode)
return result;
else if (target != 0)
{
convert_move (target, result, 0);
return target;
}
else
return convert_to_mode (mode, result, 0); return convert_to_mode (mode, result, 0);
} }
#endif /* HAVE_cmpmemsi. */
return NULL_RTX; result = target;
if (! (result != 0
&& REG_P (result) && GET_MODE (result) == mode
&& REGNO (result) >= FIRST_PSEUDO_REGISTER))
result = gen_reg_rtx (mode);
emit_library_call_value (memcmp_libfunc, result, LCT_PURE,
TYPE_MODE (integer_type_node), 3,
XEXP (arg1_rtx, 0), Pmode,
XEXP (arg2_rtx, 0), Pmode,
convert_to_mode (TYPE_MODE (sizetype), arg3_rtx,
TYPE_UNSIGNED (sizetype)),
TYPE_MODE (sizetype));
return result;
} }
/* Expand expression EXP, which is a call to the strcmp builtin. Return NULL_RTX /* Expand expression EXP, which is a call to the strcmp builtin. Return NULL_RTX
...@@ -4137,9 +4121,9 @@ expand_builtin_strcmp (tree exp, ATTRIBUTE_UNUSED rtx target) ...@@ -4137,9 +4121,9 @@ expand_builtin_strcmp (tree exp, ATTRIBUTE_UNUSED rtx target)
if (len && !TREE_SIDE_EFFECTS (len)) if (len && !TREE_SIDE_EFFECTS (len))
{ {
arg3_rtx = expand_normal (len); arg3_rtx = expand_normal (len);
result = expand_cmpstrn (cmpstrn_icode, target, arg1_rtx, result = expand_cmpstrn_or_cmpmem
arg2_rtx, TREE_TYPE (len), arg3_rtx, (cmpstrn_icode, target, arg1_rtx, arg2_rtx, TREE_TYPE (len),
MIN (arg1_align, arg2_align)); arg3_rtx, MIN (arg1_align, arg2_align));
} }
} }
...@@ -4249,9 +4233,9 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target, ...@@ -4249,9 +4233,9 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target,
arg1_rtx = get_memory_rtx (arg1, len); arg1_rtx = get_memory_rtx (arg1, len);
arg2_rtx = get_memory_rtx (arg2, len); arg2_rtx = get_memory_rtx (arg2, len);
arg3_rtx = expand_normal (len); arg3_rtx = expand_normal (len);
result = expand_cmpstrn (cmpstrn_icode, target, arg1_rtx, arg2_rtx, result = expand_cmpstrn_or_cmpmem (cmpstrn_icode, target, arg1_rtx,
TREE_TYPE (len), arg3_rtx, arg2_rtx, TREE_TYPE (len), arg3_rtx,
MIN (arg1_align, arg2_align)); MIN (arg1_align, arg2_align));
if (result) if (result)
{ {
/* Return the value in the proper mode for this function. */ /* Return the value in the proper mode for this function. */
...@@ -6346,7 +6330,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, ...@@ -6346,7 +6330,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
case BUILT_IN_BCMP: case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP: case BUILT_IN_MEMCMP:
target = expand_builtin_memcmp (exp, target, mode); target = expand_builtin_memcmp (exp, target);
if (target) if (target)
return target; return target;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment