diff mbox

[SH] Check for 0 length with inlined strnlen builtin

Message ID 54ABD16D.9000508@st.com
State New
Headers show

Commit Message

Christian Bruel Jan. 6, 2015, 12:13 p.m. UTC
> Please use 'gen_cmpeqsi_t (len, const0_rtx)' for comparing a value
> against zero instead of the bit test insn.

OK, also then OK to replace the other occurrences of the idiom for 
coding consistency ? (not sure if I could commit this as obvious ?).

Cheers

Christian

Comments

Oleg Endo Jan. 7, 2015, 10:23 a.m. UTC | #1
On Tue, 2015-01-06 at 13:13 +0100, Christian Bruel wrote:
> > Please use 'gen_cmpeqsi_t (len, const0_rtx)' for comparing a value
> > against zero instead of the bit test insn.
> 
> OK, also then OK to replace the other occurrences of the idiom for 
> coding consistency ? (not sure if I could commit this as obvious ?).

In the end the same "tst reg,reg" instruction will be generated, but
with one reg operand instead of two.  It might have some impact on the
register allocation in some cases.  If it passes testing, it's OK I
think.

Cheers,
Oleg
diff mbox

Patch

2015-01-08  Christian Bruel  <christian.bruel@st.com>

	* config/sh/sh-mem.cc (sh_expand_cmpnstr, sh_expand_setmem):
	 Use gen_cmpeqsi instead of gen_tstsi for comparing against 0.

Index: gcc/config/sh/sh-mem.cc
===================================================================
--- gcc/config/sh/sh-mem.cc	(revision 219257)
+++ gcc/config/sh/sh-mem.cc	(working copy)
@@ -410,7 +410,7 @@ 
 	  else
 	    {
 	      emit_insn (gen_addsi3 (lenw, lenw, GEN_INT (-1)));
-	      emit_insn (gen_tstsi_t (lenw, lenw));
+             emit_insn (gen_cmpeqsi_t (lenw, const0_rtx));
 	    }
 
 	  jump = emit_jump_insn (gen_branch_false (L_loop_long));
@@ -531,7 +531,7 @@ 
   else
     {
       emit_insn (gen_addsi3 (len, len, GEN_INT (-1)));
-      emit_insn (gen_tstsi_t (len, len));
+      emit_insn (gen_cmpeqsi_t (len, const0_rtx));
     }
 
   jump = emit_jump_insn (gen_branch_false (L_loop_byte));
@@ -691,7 +691,7 @@ 
       else
 	{
 	  emit_insn (gen_addsi3 (lenw, lenw, GEN_INT (-1)));
-	  emit_insn (gen_tstsi_t (lenw, lenw));
+         emit_insn (gen_cmpeqsi_t (lenw, const0_rtx));
 	}
 
       emit_move_insn (dest, val);
@@ -728,7 +728,7 @@ 
   else
     {
       emit_insn (gen_addsi3 (len, len, GEN_INT (-1)));
-      emit_insn (gen_tstsi_t (len, len));
+      emit_insn (gen_cmpeqsi_t (len, const0_rtx));
     }
 
   val = gen_lowpart (QImode, val);