Commit a4f9edf3 by Richard Biener Committed by Richard Biener

re PR tree-optimization/87314 (pointless comparison of malloc result to a string not eliminated)

2019-05-03  Richard Biener  <rguenther@suse.de>

	PR middle-end/87314
	* match.pd (cmp (convert1?@2 addr@0) (convert2? addr@1)):
	Handle STRING_CST vs DECL or STRING_CST.

	* gcc.dg/pr87314-1.c: New testcase.

From-SVN: r270845
parent a7eb97ad
2019-05-03 Richard Biener <rguenther@suse.de>
PR middle-end/87314
* match.pd (cmp (convert1?@2 addr@0) (convert2? addr@1)):
Handle STRING_CST vs DECL or STRING_CST.
2019-05-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/88963
* tree-ssa-forwprop.c (pass_forwprop::execute): Rewrite
vector loads feeding only BIT_FIELD_REFs to component
......
......@@ -3905,7 +3905,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
equal = (base0 == base1);
if (equal == 0)
{
if (!DECL_P (base0) || !DECL_P (base1))
HOST_WIDE_INT ioff0 = -1, ioff1 = -1;
off0.is_constant (&ioff0);
off1.is_constant (&ioff1);
if ((DECL_P (base0) && TREE_CODE (base1) == STRING_CST)
|| (TREE_CODE (base0) == STRING_CST && DECL_P (base1))
|| (TREE_CODE (base0) == STRING_CST
&& TREE_CODE (base1) == STRING_CST
&& ioff0 >= 0 && ioff1 >= 0
&& ioff0 < TREE_STRING_LENGTH (base0)
&& ioff1 < TREE_STRING_LENGTH (base1)
/* This is a too conservative test that the STRING_CSTs
will not end up being string-merged. */
&& strncmp (TREE_STRING_POINTER (base0) + ioff0,
TREE_STRING_POINTER (base1) + ioff1,
MIN (TREE_STRING_LENGTH (base0) - ioff0,
TREE_STRING_LENGTH (base1) - ioff1)) != 0))
;
else if (!DECL_P (base0) || !DECL_P (base1))
equal = 2;
else if (cmp != EQ_EXPR && cmp != NE_EXPR)
equal = 2;
......
2019-05-03 Richard Biener <rguenther@suse.de>
PR middle-end/87314
* gcc.dg/pr87314-1.c: New testcase.
2019-05-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/88963
* gcc.dg/tree-ssa/ssa-fre-31.c: Disable forwprop.
* gcc.target/i386/pr88963-1.c: New testcase.
......
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-original" } */
int f(){ int a; return &a==(void *)"hello"; }
int g(){ return "bye"=="hello"; }
int h() { return "bye"=="hellobye"+5; }
/* { dg-final { scan-tree-dump-times "hello" 1 "original" } } */
/* The test in h() should be retained because the result depends on
string merging. */
/* { dg-final { scan-assembler "hello" } } */
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