]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins: Fix up ICE in inline_string_cmp [PR109258]
authorJakub Jelinek <jakub@redhat.com>
Fri, 24 Mar 2023 09:38:42 +0000 (10:38 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 24 Mar 2023 09:38:42 +0000 (10:38 +0100)
The PR109086 r13-6690 inline_string_cmp change to
      if (diff != result)
        emit_move_insn (result, diff);
regressed
FAIL: go.test/test/fixedbugs/bug207.go,  -O2 -g  (internal compiler error: in emit_move_insn, at expr.cc:4224)
The problem is the Go FE doesn't mark __builtin_memcmp as pure (I'll also
send patch for that) and so result is const0_rtx when the call lost its lhs
and the above move ICEs because moving something into const0_rtx is obviously
invalid.
I think it is better not to rely on all FEs having these *cmp functions
pure anD DCE being performed.  The following patch just punts from the
inline expansion in that case, so we just emit normal library call.

2023-03-24  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/109258
* builtins.cc (inline_expand_builtin_bytecmp): Return NULL_RTX early
if target == const0_rtx.

gcc/builtins.cc

index 8026e2001b752f30cd5b9abb88673c2bae5e464e..ed0efd5c8b3159f70a6ffd754bff1877de51a391 100644 (file)
@@ -7178,8 +7178,8 @@ inline_expand_builtin_bytecmp (tree exp, rtx target)
   bool is_ncmp = (fcode == BUILT_IN_STRNCMP || fcode == BUILT_IN_MEMCMP);
 
   /* Do NOT apply this inlining expansion when optimizing for size or
-     optimization level below 2.  */
-  if (optimize < 2 || optimize_insn_for_size_p ())
+     optimization level below 2 or if unused *cmp hasn't been DCEd.  */
+  if (optimize < 2 || optimize_insn_for_size_p () || target == const0_rtx)
     return NULL_RTX;
 
   gcc_checking_assert (fcode == BUILT_IN_STRCMP