@@ -1,6 +1,15 @@
2011-01-19 H.J. Lu <hongjiu.lu@intel.com>
PR target/47364
+ * builtins.c (expand_builtin_strlen): Convert to Pmode if PAT
+ isn't in Pmode.
+
+ * config/i386/i386.c (ix86_expand_strlen): Handle GET_MODE (out)
+ != Pmode.
+
+2011-01-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/47364
* config/i386/i386.c (ix86_legitimize_address): Convert to
Pmode if needed.
@@ -3436,7 +3436,11 @@ expand_builtin_strlen (tree exp, rtx target,
start_sequence ();
pat = expand_expr (src, src_reg, ptr_mode, EXPAND_NORMAL);
if (pat != src_reg)
- emit_move_insn (src_reg, pat);
+ {
+ if (GET_MODE (pat) != Pmode)
+ pat = convert_to_mode (Pmode, pat, 1);
+ emit_move_insn (src_reg, pat);
+ }
pat = get_insns ();
end_sequence ();
@@ -21661,6 +21661,8 @@ ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
often used and I use one fewer register for the lifetime of
output_strlen_unroll() this is better. */
+ if (GET_MODE (out) != Pmode)
+ out = convert_to_mode (Pmode, out, 1);
emit_move_insn (out, addr);
ix86_expand_strlensi_unroll_1 (out, src, align);
@@ -21692,7 +21694,15 @@ ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
scratch4), UNSPEC_SCAS);
emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
emit_insn (ix86_gen_one_cmpl2 (scratch2, scratch1));
- emit_insn (ix86_gen_add3 (out, scratch2, constm1_rtx));
+ if (GET_MODE (out) != Pmode)
+ {
+ rtx scratch5 = gen_reg_rtx (Pmode);
+ emit_insn (ix86_gen_add3 (scratch5, scratch2, constm1_rtx));
+ scratch5 = convert_to_mode (GET_MODE (out), scratch5, 1);
+ emit_move_insn (out, scratch5);
+ }
+ else
+ emit_insn (ix86_gen_add3 (out, scratch2, constm1_rtx));
}
return true;
}
@@ -1,5 +1,10 @@
2011-01-19 H.J. Lu <hongjiu.lu@intel.com>
+ PR target/47364
+ * gcc.target/i386/pr47364-2.c: New.
+
+2011-01-19 H.J. Lu <hongjiu.lu@intel.com>
+
* gcc.target/i386/pr47364.c: Moved to ...
* gcc.target/i386/pr47364-1.c: This.
new file mode 100644
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern __SIZE_TYPE__ strlen (const char *);
+void foo (char *, const char *);
+int bar (const char *prefix)
+{
+ char buff[256];
+ foo (buff, prefix);
+ return strlen(buff);
+}