re PR tree-optimization/78847 (pointer arithmetic from c++ ranged-based for loop not optimized)

2017-04-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/78847
	* fold-const.c (split_tree): Handle POINTER_PLUS_EXPR.

	* g++.dg/tree-ssa/pr78847.C: New testcase.

From-SVN: r247061
This commit is contained in:
Richard Biener 2017-04-21 12:09:20 +00:00 committed by Richard Biener
parent e1478a0ee9
commit bb1bc604a8
4 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2017-04-21 Richard Biener <rguenther@suse.de>
PR tree-optimization/78847
* fold-const.c (split_tree): Handle POINTER_PLUS_EXPR.
2017-04-21 Richard Biener <rguenther@suse.de> 2017-04-21 Richard Biener <rguenther@suse.de>
* tree.h (build_qualified_type): Annotate with CXX_MEM_STAT_INFO. * tree.h (build_qualified_type): Annotate with CXX_MEM_STAT_INFO.

View File

@ -798,8 +798,11 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code,
though the C standard doesn't say so) for integers because though the C standard doesn't say so) for integers because
the value is not affected. For reals, the value might be the value is not affected. For reals, the value might be
affected, so we can't. */ affected, so we can't. */
&& ((code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR) && ((code == PLUS_EXPR && TREE_CODE (in) == POINTER_PLUS_EXPR)
|| (code == MINUS_EXPR && TREE_CODE (in) == PLUS_EXPR)))) || (code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
|| (code == MINUS_EXPR
&& (TREE_CODE (in) == PLUS_EXPR
|| TREE_CODE (in) == POINTER_PLUS_EXPR)))))
{ {
tree op0 = TREE_OPERAND (in, 0); tree op0 = TREE_OPERAND (in, 0);
tree op1 = TREE_OPERAND (in, 1); tree op1 = TREE_OPERAND (in, 1);

View File

@ -1,3 +1,8 @@
2017-04-21 Richard Biener <rguenther@suse.de>
PR tree-optimization/78847
* g++.dg/tree-ssa/pr78847.C: New testcase.
2017-04-21 Jakub Jelinek <jakub@redhat.com> 2017-04-21 Jakub Jelinek <jakub@redhat.com>
PR c/80468 PR c/80468

View File

@ -0,0 +1,26 @@
/* { dg-do compile } */
/* { dg-require-effective-target c++14 } */
/* { dg-options "-O3 -fdump-tree-ldist" } */
#include <stddef.h>
#include <cstring>
#include <experimental/string_view>
using string_view = std::experimental::string_view;
class Foo {
constexpr static size_t Length = 9;
char ascii_[Length];
public:
Foo();
string_view view() const {
return string_view(ascii_, Length);
}
};
void testWithLoopValue(const Foo foo, size_t ptr, char *buf_) {
for (auto c : foo.view())
buf_[ptr++] = c;
}
/* { dg-final { scan-tree-dump "memcpy\[^\n\r\]*, 9\\);" "ldist" } } */