Commit 0edd264d by Aaron Sawdey Committed by Aaron Sawdey

rs6000-protos.h (expand_strn_compare): Add arg.

2017-01-18  Aaron Sawdey  <acsawdey@linux.vnet.ibm.com>
	* config/rs6000/rs6000-protos.h (expand_strn_compare): Add arg.
	* config/rs6000/rs6000.c (expand_strn_compare): Add ability to expand
	strcmp. Fix bug where comparison didn't stop with zero byte. Fix
	case where N arg is SIZE_MAX.
	* config/rs6000/rs6000.md (cmpstrnsi): Args to expand_strn_compare.
	(cmpstrsi): Add pattern.
2017-01-18  Aaron Sawdey  <acsawdey@linux.vnet.ibm.com>
	* gcc.dg/strcmp-1.c: New test.
	* gcc.dg/strncmp-1.c: Add test for a bug that escaped.

From-SVN: r244598
parent 551914b7
2017-01-18 Aaron Sawdey <acsawdey@linux.vnet.ibm.com>
* config/rs6000/rs6000-protos.h (expand_strn_compare): Add arg.
* config/rs6000/rs6000.c (expand_strn_compare): Add ability to expand
strcmp. Fix bug where comparison didn't stop with zero byte. Fix
case where N arg is SIZE_MAX.
* config/rs6000/rs6000.md (cmpstrnsi): Args to expand_strn_compare.
(cmpstrsi): Add pattern.
2017-01-18 Michael Meissner <meissner@linux.vnet.ibm.com> 2017-01-18 Michael Meissner <meissner@linux.vnet.ibm.com>
* config/rs6000/rs6000-c.c (altivec_overloaded_builtins): Add * config/rs6000/rs6000-c.c (altivec_overloaded_builtins): Add
......
...@@ -78,7 +78,7 @@ extern void rs6000_scale_v2df (rtx, rtx, int); ...@@ -78,7 +78,7 @@ extern void rs6000_scale_v2df (rtx, rtx, int);
extern int expand_block_clear (rtx[]); extern int expand_block_clear (rtx[]);
extern int expand_block_move (rtx[]); extern int expand_block_move (rtx[]);
extern bool expand_block_compare (rtx[]); extern bool expand_block_compare (rtx[]);
extern bool expand_strn_compare (rtx[]); extern bool expand_strn_compare (rtx[], int);
extern const char * rs6000_output_load_multiple (rtx[]); extern const char * rs6000_output_load_multiple (rtx[]);
extern bool rs6000_is_valid_mask (rtx, int *, int *, machine_mode); extern bool rs6000_is_valid_mask (rtx, int *, int *, machine_mode);
extern bool rs6000_is_valid_and_mask (rtx, machine_mode); extern bool rs6000_is_valid_and_mask (rtx, machine_mode);
......
...@@ -9102,7 +9102,26 @@ ...@@ -9102,7 +9102,26 @@
(use (match_operand:SI 4))])] (use (match_operand:SI 4))])]
"TARGET_CMPB && (BYTES_BIG_ENDIAN || TARGET_LDBRX)" "TARGET_CMPB && (BYTES_BIG_ENDIAN || TARGET_LDBRX)"
{ {
if (expand_strn_compare (operands)) if (expand_strn_compare (operands, 0))
DONE;
else
FAIL;
})
;; String compare insn.
;; Argument 0 is the target (result)
;; Argument 1 is the destination
;; Argument 2 is the source
;; Argument 3 is the alignment
(define_expand "cmpstrsi"
[(parallel [(set (match_operand:SI 0)
(compare:SI (match_operand:BLK 1)
(match_operand:BLK 2)))
(use (match_operand:SI 3))])]
"TARGET_CMPB && (BYTES_BIG_ENDIAN || TARGET_LDBRX)"
{
if (expand_strn_compare (operands, 1))
DONE; DONE;
else else
FAIL; FAIL;
......
2017-01-18 Aaron Sawdey <acsawdey@linux.vnet.ibm.com>
* gcc.dg/strcmp-1.c: New test.
* gcc.dg/strncmp-1.c: Add test for a bug that escaped.
2017-01-18 David Malcolm <dmalcolm@redhat.com> 2017-01-18 David Malcolm <dmalcolm@redhat.com>
* jit.dg/test-threads.c (dejagnu_pass): Remove decl. * jit.dg/test-threads.c (dejagnu_pass): Remove decl.
......
/* Test memcmp builtin expansion for compilation and proper execution. */ /* Test strncmp builtin expansion for compilation and proper execution. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-options "-O2" } */ /* { dg-options "-O2" } */
/* { dg-require-effective-target ptr32plus } */ /* { dg-require-effective-target ptr32plus } */
...@@ -32,31 +32,32 @@ static void test_strncmp_ ## SZ ## _ ## ALIGN (void) { \ ...@@ -32,31 +32,32 @@ static void test_strncmp_ ## SZ ## _ ## ALIGN (void) { \
a[SZ] = 0; \ a[SZ] = 0; \
b[SZ] = 0; \ b[SZ] = 0; \
if (!((r1 = strncmp (b, a, SZ)) > 0)) \ if (!((r1 = strncmp (b, a, SZ)) > 0)) \
{ \ abort (); \
abort (); \
} \
if (!((r1 = strncmp (a, b, SZ)) < 0)) \ if (!((r1 = strncmp (a, b, SZ)) < 0)) \
{ \ abort (); \
abort (); \
} \
b[i] = '1'; \ b[i] = '1'; \
if (!((r1 = strncmp (a, b, SZ)) == 0)) \ if (!((r1 = strncmp (a, b, SZ)) == 0)) \
{ \ abort (); \
abort (); \
} \
for(j = i; j < SZ ; j++) \ for(j = i; j < SZ ; j++) \
{ \ { \
a[j] = '1'; \ a[j] = '1'; \
b[j] = '2'; \ b[j] = '2'; \
} \ } \
if (!((r1 = strncmp(b, a, SZ)) > 0)) \ if (!((r1 = strncmp (b, a, SZ)) > 0)) \
{ \ abort (); \
abort (); \ if (!((r1 = strncmp (a, b, SZ)) < 0)) \
} \ abort (); \
if (!((r1 = strncmp(a, b, SZ)) < 0)) \ for(j = 0; j < i ; j++) \
{ \ { \
abort (); \ memset(a, '-', SZ); \
} \ memset(b, '-', SZ); \
a[j] = '\0'; \
a[j+1] = '1'; \
b[j] = '\0'; \
b[j+1] = '2'; \
if ((r1 = strncmp (b, a, SZ)) != 0) \
abort (); \
} \
a = three + 4096 - (SZ / 2 + (i & 1) * ALIGN); \ a = three + 4096 - (SZ / 2 + (i & 1) * ALIGN); \
b = four + 4096 - (SZ / 2 + (i & 1) * ALIGN); \ b = four + 4096 - (SZ / 2 + (i & 1) * ALIGN); \
memset(a, '-', SZ); \ memset(a, '-', SZ); \
...@@ -66,18 +67,12 @@ static void test_strncmp_ ## SZ ## _ ## ALIGN (void) { \ ...@@ -66,18 +67,12 @@ static void test_strncmp_ ## SZ ## _ ## ALIGN (void) { \
a[SZ] = 0; \ a[SZ] = 0; \
b[SZ] = 0; \ b[SZ] = 0; \
if (!((r1 = strncmp(b, a, SZ)) > 0)) \ if (!((r1 = strncmp(b, a, SZ)) > 0)) \
{ \ abort (); \
abort (); \
} \
if (!((r1 = strncmp(a, b, SZ)) < 0)) \ if (!((r1 = strncmp(a, b, SZ)) < 0)) \
{ \ abort (); \
abort (); \
} \
b[i] = '1'; \ b[i] = '1'; \
if (!((r1 = strncmp(a, b, SZ)) == 0)) \ if (!((r1 = strncmp(a, b, SZ)) == 0)) \
{ \ abort (); \
abort (); \
} \
} \ } \
} }
...@@ -327,6 +322,11 @@ DEF_TEST(49,2) ...@@ -327,6 +322,11 @@ DEF_TEST(49,2)
DEF_TEST(49,4) DEF_TEST(49,4)
DEF_TEST(49,8) DEF_TEST(49,8)
DEF_TEST(49,16) DEF_TEST(49,16)
DEF_TEST(100,1)
DEF_TEST(100,2)
DEF_TEST(100,4)
DEF_TEST(100,8)
DEF_TEST(100,16)
#else #else
DEF_TEST(3,1) DEF_TEST(3,1)
DEF_TEST(4,1) DEF_TEST(4,1)
...@@ -350,6 +350,11 @@ DEF_TEST(32,2) ...@@ -350,6 +350,11 @@ DEF_TEST(32,2)
DEF_TEST(32,4) DEF_TEST(32,4)
DEF_TEST(32,8) DEF_TEST(32,8)
DEF_TEST(32,16) DEF_TEST(32,16)
DEF_TEST(100,1)
DEF_TEST(100,2)
DEF_TEST(100,4)
DEF_TEST(100,8)
DEF_TEST(100,16)
#endif #endif
int int
......
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