On Fri, Oct 7, 2016 at 10:39 AM, Martin Liška <[email protected]> wrote:
> I'm resending the patch, where I implemented all builtins mentions in subject
> in gimp-fold.c.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>
> Ready to be installed?
+ case BUILT_IN_STRNCASECMP:
+ {
+ r = strncmp (p1, p2, length);
+ if (r == 0)
+ known_result = true;
length might be -1 here -- I think you need to guard against that (but you can
handle BUILT_IN_STRCASECMP which you miss?). Likewise for the strncmp case.
Also do we know whether the c_getstr () result is '\0'-terminated? AFAICS these
constant foldings were not implemented in builtins.c, I see a STRCMP one in
fold-const-call.c though. I believe the STRING_CST string is not guaranteed to
be '\0' terminated (STRING_CST comes with explicit length).
+ tree temp = fold_build2_loc (loc, MEM_REF, cst_uchar_node, str1,
+ off0);
+ temp = gimple_build (&stmts, loc, NOP_EXPR, cst_uchar_node, temp);
please don't use gimple_build here, there is nothing to simplify for it. Using
a NOP_EXPR is also confusing (to match the API...). Just do
gimple_build_assign (make_ssa_name (...), ..) like other folders do.
+ replace_call_with_value (gsi, fold_convert_loc (loc, type, temp));
and you'd want to replace the call with the MEM_REF stmt using
gsi_replace_with_seq_vops as you fail to set virtual operands properly
above (thus you'll get ICEs when this only matches during GIMPLE opts).
+ location_t loc = gimple_location (stmt);
+ tree cst_uchar_node = build_type_variant (unsigned_char_type_node, 1, 0);
+ tree cst_uchar_ptr_node
+ = build_pointer_type_for_mode (cst_uchar_node, ptr_mode, true);
+ tree off0 = build_int_cst (cst_uchar_ptr_node, 0);
it would be nice to not do this tree building if nothign is folded.
+ case BUILT_IN_STRCMP:
+ return gimple_fold_builtin_string_compare (gsi);
+ case BUILT_IN_STRCASECMP:
+ return gimple_fold_builtin_string_compare (gsi);
+ case BUILT_IN_STRNCMP:
+ return gimple_fold_builtin_string_compare (gsi);
+ case BUILT_IN_STRNCASECMP:
+ return gimple_fold_builtin_string_compare (gsi);
please do
+ case BUILT_IN_STRCMP:
+ case BUILT_IN_STRCASECMP:
...
+ return gimple_fold_builtin_string_compare (gsi);
Thanks,
Richard.
> Martin