[Sync] Sync patch from openeuler/gcc

(cherry picked from commit 63828598f16b978ef91ea80730b8c13a698bfbb0)
This commit is contained in:
Mingchuan Wu 2023-11-29 20:20:05 +08:00 committed by openeuler-sync-bot
parent 61857d12bc
commit e3967b0b94
20 changed files with 1825 additions and 1 deletions

View File

@ -0,0 +1,52 @@
From 41af6d361a6d85ef4fce8a8438113d765596afdd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=83=91=E6=99=A8=E5=8D=89?= <zhengchenhui1@huawei.com>
Date: Thu, 12 Oct 2023 10:19:29 +0800
Subject: [PATCH 08/26] [DFE]Fix internal compiler error with
-fipa-struct-reorg=3.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 14 +++++++++++---
gcc/testsuite/gcc.dg/struct/struct-reorg.exp | 2 ++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 367bcf210..53d026386 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -3991,9 +3991,17 @@ ipa_struct_reorg::maybe_mark_or_record_other_side (tree side, tree other, gimple
if (VOID_POINTER_P (TREE_TYPE (side))
&& TREE_CODE (side) == SSA_NAME)
{
- /* The type is other, the declaration is side. */
- current_function->record_decl (type, side, -1,
- isptrptr (TREE_TYPE (other)) ? TREE_TYPE (other) : NULL);
+ tree inner = SSA_NAME_VAR (side);
+ if (inner)
+ {
+ srdecl *in = find_decl (inner);
+ if (in && !in->type->has_escaped ())
+ {
+ /* The type is other, the declaration is side. */
+ current_function->record_decl (type, side, -1,
+ isptrptr (TREE_TYPE (other)) ? TREE_TYPE (other) : NULL);
+ }
+ }
}
else
{
diff --git a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
index 281046b48..107f990f5 100644
--- a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
+++ b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
@@ -84,6 +84,8 @@ gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/rf*.c]] \
# -fipa-struct-reorg=3
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/dfe*.c]] \
"" "-fipa-struct-reorg=3 -fdump-ipa-all -flto-partition=one -fwhole-program"
+gcc-dg-runtest $srcdir/$subdir/struct_reorg-7.c \
+ "" "-fipa-struct-reorg=3 -fdump-ipa-all -flto-partition=one -fwhole-program"
# -fipa-struct-reorg=4
gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/pc*.c]] \
--
2.27.0

View File

@ -0,0 +1,82 @@
From 364cff1c26b9d1ef017e4bd2b080e1ca53f14694 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Tue, 12 May 2020 09:01:12 +0100
Subject: [PATCH 09/26] tree-vect-generic: Tweak build_replicated_const
[PR94980 2/3]
This patch makes build_replicated_const take the number of bits
in VALUE rather than calculating the width from the element type.
The callers can then use vector_element_bits to calculate the
correct element size from the vector type.
2020-05-12 Richard Sandiford <richard.sandiford@arm.com>
gcc/
PR tree-optimization/94980
* tree-vect-generic.c (build_replicated_const): Take the number
of bits as a parameter, instead of the type of the elements.
(do_plus_minus): Update accordingly, using vector_element_bits
to calculate the correct number of bits.
(do_negate): Likewise.
Reference commit in GCC: 14605b6bd8c37fffd8065c5c3fe6b1b9d7b2a294
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/tree-vect-generic.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index 0ec4412bc..82fb0ae7c 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -67,11 +67,10 @@ subparts_gt (tree type1, tree type2)
}
/* Build a constant of type TYPE, made of VALUE's bits replicated
- every TYPE_SIZE (INNER_TYPE) bits to fit TYPE's precision. */
+ every WIDTH bits to fit TYPE's precision. */
static tree
-build_replicated_const (tree type, tree inner_type, HOST_WIDE_INT value)
+build_replicated_const (tree type, unsigned int width, HOST_WIDE_INT value)
{
- int width = tree_to_uhwi (TYPE_SIZE (inner_type));
int n = (TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
/ HOST_BITS_PER_WIDE_INT;
unsigned HOST_WIDE_INT low, mask;
@@ -214,13 +213,14 @@ do_plus_minus (gimple_stmt_iterator *gsi, tree word_type, tree a, tree b,
tree bitpos ATTRIBUTE_UNUSED, tree bitsize ATTRIBUTE_UNUSED,
enum tree_code code, tree type ATTRIBUTE_UNUSED)
{
+ unsigned int width = vector_element_bits (TREE_TYPE (a));
tree inner_type = TREE_TYPE (TREE_TYPE (a));
unsigned HOST_WIDE_INT max;
tree low_bits, high_bits, a_low, b_low, result_low, signs;
max = GET_MODE_MASK (TYPE_MODE (inner_type));
- low_bits = build_replicated_const (word_type, inner_type, max >> 1);
- high_bits = build_replicated_const (word_type, inner_type, max & ~(max >> 1));
+ low_bits = build_replicated_const (word_type, width, max >> 1);
+ high_bits = build_replicated_const (word_type, width, max & ~(max >> 1));
a = tree_vec_extract (gsi, word_type, a, bitsize, bitpos);
b = tree_vec_extract (gsi, word_type, b, bitsize, bitpos);
@@ -247,13 +247,14 @@ do_negate (gimple_stmt_iterator *gsi, tree word_type, tree b,
enum tree_code code ATTRIBUTE_UNUSED,
tree type ATTRIBUTE_UNUSED)
{
+ unsigned int width = vector_element_bits (TREE_TYPE (b));
tree inner_type = TREE_TYPE (TREE_TYPE (b));
HOST_WIDE_INT max;
tree low_bits, high_bits, b_low, result_low, signs;
max = GET_MODE_MASK (TYPE_MODE (inner_type));
- low_bits = build_replicated_const (word_type, inner_type, max >> 1);
- high_bits = build_replicated_const (word_type, inner_type, max & ~(max >> 1));
+ low_bits = build_replicated_const (word_type, width, max >> 1);
+ high_bits = build_replicated_const (word_type, width, max & ~(max >> 1));
b = tree_vec_extract (gsi, word_type, b, bitsize, bitpos);
--
2.27.0

View File

@ -0,0 +1,82 @@
From fe61a1c365661a717220d0917e034899559aafbb Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Tue, 12 May 2020 09:01:13 +0100
Subject: [PATCH 10/26] tree-vect-generic: Fix bitfield widths [PR94980 3/3]
This third patch of three actually fixes the PR. We were using
8-bit BIT_FIELD_REFs to access single-bit elements, and multiplying
the vector index by 8 bits rather than 1 bit.
2020-05-12 Richard Sandiford <richard.sandiford@arm.com>
gcc/
PR tree-optimization/94980
* tree-vect-generic.c (expand_vector_comparison): Use
vector_element_bits_tree to get the element size in bits,
rather than using TYPE_SIZE.
(expand_vector_condition, vector_element): Likewise.
gcc/testsuite/
PR tree-optimization/94980
* gcc.target/i386/pr94980.c: New test.
Reference commit in GCC: 4c0283b9ad75b128b79c507d78d678123fe9f471
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/testsuite/gcc.target/i386/pr94980.c | 10 ++++++++++
gcc/tree-vect-generic.c | 6 +++---
2 files changed, 13 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr94980.c
diff --git a/gcc/testsuite/gcc.target/i386/pr94980.c b/gcc/testsuite/gcc.target/i386/pr94980.c
new file mode 100644
index 000000000..488f94abe
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94980.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512vl" } */
+
+int __attribute__((__vector_size__(16))) v;
+
+void
+foo(void)
+{
+ 0 <= (0 != v) >= 0;
+}
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index 82fb0ae7c..f0c28c97a 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -390,7 +390,7 @@ expand_vector_comparison (gimple_stmt_iterator *gsi, tree type, tree op0,
(TREE_TYPE (type)))))
{
tree inner_type = TREE_TYPE (TREE_TYPE (op0));
- tree part_width = TYPE_SIZE (inner_type);
+ tree part_width = vector_element_bits_tree (TREE_TYPE (op0));
tree index = bitsize_int (0);
int nunits = nunits_for_known_piecewise_op (TREE_TYPE (op0));
int prec = GET_MODE_PRECISION (SCALAR_TYPE_MODE (type));
@@ -946,9 +946,9 @@ expand_vector_condition (gimple_stmt_iterator *gsi)
vec<constructor_elt, va_gc> *v;
tree constr;
tree inner_type = TREE_TYPE (type);
+ tree width = vector_element_bits_tree (type);
tree cond_type = TREE_TYPE (TREE_TYPE (a));
tree comp_inner_type = cond_type;
- tree width = TYPE_SIZE (inner_type);
tree index = bitsize_int (0);
tree comp_width = width;
tree comp_index = index;
@@ -1342,7 +1342,7 @@ vector_element (gimple_stmt_iterator *gsi, tree vect, tree idx, tree *ptmpvec)
}
else
{
- tree size = TYPE_SIZE (vect_elt_type);
+ tree size = vector_element_bits_tree (vect_type);
tree pos = fold_build2 (MULT_EXPR, bitsizetype, bitsize_int (index),
size);
return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
--
2.27.0

View File

@ -0,0 +1,88 @@
From 189fe23d846e3e701d1fba7605b96ee3b07799a3 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 9 Mar 2020 13:23:03 +0100
Subject: [PATCH 11/26] Lower VEC_COND_EXPR into internal functions.
gcc/ChangeLog:
* Makefile.in: Add new file.
* expr.c (expand_expr_real_2): Add gcc_unreachable as we should
not meet this condition.
(do_store_flag): Likewise.
* gimplify.c (gimplify_expr): Gimplify first argument of
VEC_COND_EXPR to be a SSA name.
* internal-fn.c (vec_cond_mask_direct): New.
(vec_cond_direct): Likewise.
(vec_condu_direct): Likewise.
(vec_condeq_direct): Likewise.
(expand_vect_cond_optab_fn): New.
(expand_vec_cond_optab_fn): Likewise.
(expand_vec_condu_optab_fn): Likewise.
(expand_vec_condeq_optab_fn): Likewise.
(expand_vect_cond_mask_optab_fn): Likewise.
(expand_vec_cond_mask_optab_fn): Likewise.
(direct_vec_cond_mask_optab_supported_p): Likewise.
(direct_vec_cond_optab_supported_p): Likewise.
(direct_vec_condu_optab_supported_p): Likewise.
(direct_vec_condeq_optab_supported_p): Likewise.
* internal-fn.def (VCOND): New OPTAB.
(VCONDU): Likewise.
(VCONDEQ): Likewise.
(VCOND_MASK): Likewise.
* optabs.c (get_rtx_code): Make it global.
(expand_vec_cond_mask_expr): Removed.
(expand_vec_cond_expr): Removed.
* optabs.h (expand_vec_cond_expr): Likewise.
(vector_compare_rtx): Make it global.
* passes.def: Add new pass_gimple_isel pass.
* tree-cfg.c (verify_gimple_assign_ternary): Add check
for VEC_COND_EXPR about first argument.
* tree-pass.h (make_pass_gimple_isel): New.
* tree-ssa-forwprop.c (pass_forwprop::execute): Prevent
propagation of the first argument of a VEC_COND_EXPR.
* tree-ssa-reassoc.c (ovce_extract_ops): Support SSA_NAME as
first argument of a VEC_COND_EXPR.
(optimize_vec_cond_expr): Likewise.
* tree-vect-generic.c (expand_vector_divmod): Make SSA_NAME
for a first argument of created VEC_COND_EXPR.
(expand_vector_condition): Fix coding style.
* tree-vect-stmts.c (vectorizable_condition): Gimplify
first argument.
* gimple-isel.cc: New file.
gcc/testsuite/ChangeLog:
* g++.dg/vect/vec-cond-expr-eh.C: New test.
Reference commit in GCC: 502d63b6d6141597bb18fd23c87736a1b384cf8f
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/tree-vect-stmts.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 98b233718..0e1c86af6 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -11281,12 +11281,12 @@ vectorizable_condition (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
{
vec_cond_rhs = vec_oprnds1[i];
if (bitop1 == NOP_EXPR)
- {
- gimple_seq stmts = NULL;
- vec_compare = gimple_build (&stmts, cond_code, vec_cmp_type,
- vec_cond_lhs, vec_cond_rhs);
- gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
- }
+ {
+ gimple_seq stmts = NULL;
+ vec_compare = gimple_build (&stmts, cond_code, vec_cmp_type,
+ vec_cond_lhs, vec_cond_rhs);
+ gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
+ }
else
{
new_temp = make_ssa_name (vec_cmp_type);
--
2.27.0

View File

@ -0,0 +1,35 @@
From fee3fcbaa008eef0efe59e1e9eff9cc4e4767423 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 18 Jun 2020 09:11:31 +0200
Subject: [PATCH 12/26] Add missing check for gassign.
gcc/ChangeLog:
* tree-vect-generic.c (expand_vector_condition): Check
for gassign before inspecting RHS.
Reference commit in GCC: d11c9841d54ed74978f8d0e0f352631f90504dd5
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/tree-vect-generic.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index f0c28c97a..f6b8287e5 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -957,8 +957,9 @@ expand_vector_condition (gimple_stmt_iterator *gsi)
if (code == SSA_NAME)
{
- gimple *assign = SSA_NAME_DEF_STMT (a);
- if (TREE_CODE_CLASS (gimple_assign_rhs_code (assign)) == tcc_comparison)
+ gassign *assign = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (a));
+ if (assign != NULL
+ && TREE_CODE_CLASS (gimple_assign_rhs_code (assign)) == tcc_comparison)
{
a_is_comparison = true;
a1 = gimple_assign_rhs1 (assign);
--
2.27.0

View File

@ -0,0 +1,116 @@
From 2500488013903f9960fab8b49606e5d380435662 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Fri, 31 Jul 2020 14:24:26 +0200
Subject: [PATCH 13/26] Amend match.pd syntax with force-simplified results
This adds a ! marker to result expressions that should simplify
(and if not fail the simplification). This can for example be
used like
(simplify
(plus (vec_cond:s @0 @1 @2) @3)
(vec_cond @0 (plus! @1 @3) (plus! @2 @3)))
to make the simplification only apply in case both plus operations
in the result end up simplified to a simple operand.
2020-07-31 Richard Biener <rguenther@suse.de>
* genmatch.c (expr::force_leaf): Add and initialize.
(expr::gen_transform): Honor force_leaf by passing
NULL as sequence argument to maybe_push_res_to_seq.
(parser::parse_expr): Allow ! marker on result expression
operations.
* doc/match-and-simplify.texi: Amend.
Reference commit in GCC: 14c35be3bf493859b92c3c6ca7893075212169ab
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/doc/match-and-simplify.texi | 15 +++++++++++++++
gcc/genmatch.c | 19 ++++++++++++++++---
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/gcc/doc/match-and-simplify.texi b/gcc/doc/match-and-simplify.texi
index 1df8b90e7..41980acbf 100644
--- a/gcc/doc/match-and-simplify.texi
+++ b/gcc/doc/match-and-simplify.texi
@@ -361,6 +361,21 @@ Usually the types of the generated result expressions are
determined from the context, but sometimes like in the above case
it is required that you specify them explicitely.
+Another modifier for generated expressions is @code{!} which
+tells the machinery to only consider the simplification in case
+the marked expression simplified to a simple operand. Consider
+for example
+
+@smallexample
+(simplify
+ (plus (vec_cond:s @@0 @@1 @@2) @@3)
+ (vec_cond @@0 (plus! @@1 @@3) (plus! @@2 @@3)))
+@end smallexample
+
+which moves the outer @code{plus} operation to the inner arms
+of the @code{vec_cond} expression but only if the actual plus
+operations both simplify.
+
As intermediate conversions are often optional there is a way to
avoid the need to repeat patterns both with and without such
conversions. Namely you can mark a conversion as being optional
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 0a8cba62e..88459d968 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -697,12 +697,13 @@ public:
expr (id_base *operation_, location_t loc, bool is_commutative_ = false)
: operand (OP_EXPR, loc), operation (operation_),
ops (vNULL), expr_type (NULL), is_commutative (is_commutative_),
- is_generic (false), force_single_use (false), opt_grp (0) {}
+ is_generic (false), force_single_use (false), force_leaf (false),
+ opt_grp (0) {}
expr (expr *e)
: operand (OP_EXPR, e->location), operation (e->operation),
ops (vNULL), expr_type (e->expr_type), is_commutative (e->is_commutative),
is_generic (e->is_generic), force_single_use (e->force_single_use),
- opt_grp (e->opt_grp) {}
+ force_leaf (e->force_leaf), opt_grp (e->opt_grp) {}
void append_op (operand *op) { ops.safe_push (op); }
/* The operator and its operands. */
id_base *operation;
@@ -717,6 +718,9 @@ public:
/* Whether pushing any stmt to the sequence should be conditional
on this expression having a single-use. */
bool force_single_use;
+ /* Whether in the result expression this should be a leaf node
+ with any children simplified down to simple operands. */
+ bool force_leaf;
/* If non-zero, the group for optional handling. */
unsigned char opt_grp;
virtual void gen_transform (FILE *f, int, const char *, bool, int,
@@ -2520,7 +2524,8 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
fprintf (f, ");\n");
fprintf_indent (f, indent, "tem_op.resimplify (lseq, valueize);\n");
fprintf_indent (f, indent,
- "_r%d = maybe_push_res_to_seq (&tem_op, lseq);\n", depth);
+ "_r%d = maybe_push_res_to_seq (&tem_op, %s);\n", depth,
+ !force_leaf ? "lseq" : "NULL");
fprintf_indent (f, indent,
"if (!_r%d) return false;\n",
depth);
@@ -4240,6 +4245,14 @@ parser::parse_expr ()
bool force_capture = false;
const char *expr_type = NULL;
+ if (!parsing_match_operand
+ && token->type == CPP_NOT
+ && !(token->flags & PREV_WHITE))
+ {
+ eat_token (CPP_NOT);
+ e->force_leaf = true;
+ }
+
if (token->type == CPP_COLON
&& !(token->flags & PREV_WHITE))
{
--
2.27.0

View File

@ -0,0 +1,162 @@
From 907f5fa8e2611ff947b7471bca22328b053637b1 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Wed, 5 Aug 2020 12:00:07 +0200
Subject: [PATCH 14/26] Make genmatch transform failure handling more
consistent
Currently whether a fail during the transform stage is fatal or
whether following patterns are still considers is a bit random
depending on whether the pattern is wrapped in a for for example.
The follwing makes it consistent by replacing early returns with
gotos to the end of the pattern processing.
2020-08-05 Richard Biener <rguenther@suse.de>
* genmatch.c (fail_label): New global.
(expr::gen_transform): Branch to fail_label instead of
returning. Fix indent of call argument checking.
(dt_simplify::gen_1): Compute and emit fail_label, branch
to it instead of returning early.
Reference commit in GCC: f0699540f37e2550974f9049778a42a634062c0b
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/genmatch.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 88459d968..e49fd0a2e 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -2352,6 +2352,10 @@ capture_info::walk_c_expr (c_expr *e)
}
+/* The current label failing the current matched pattern during
+ code generation. */
+static char *fail_label;
+
/* Code generation off the decision tree and the refered AST nodes. */
bool
@@ -2527,8 +2531,8 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
"_r%d = maybe_push_res_to_seq (&tem_op, %s);\n", depth,
!force_leaf ? "lseq" : "NULL");
fprintf_indent (f, indent,
- "if (!_r%d) return false;\n",
- depth);
+ "if (!_r%d) goto %s;\n",
+ depth, fail_label);
if (*opr == CONVERT_EXPR)
{
indent -= 4;
@@ -2560,7 +2564,7 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
if (opr->kind != id_base::CODE)
{
fprintf_indent (f, indent, " if (!_r%d)\n", depth);
- fprintf_indent (f, indent, " return NULL_TREE;\n");
+ fprintf_indent (f, indent, " goto %s;\n", fail_label);
fprintf_indent (f, indent, "}\n");
}
if (*opr == CONVERT_EXPR)
@@ -3068,12 +3072,12 @@ dt_node::gen_kids_1 (FILE *f, int indent, bool gimple, int depth,
/* We need to be defensive against bogus prototypes allowing
calls with not enough arguments. */
fprintf_indent (f, indent,
- " if (gimple_call_num_args (_c%d) == %d)\n"
- " {\n", depth, e->ops.length ());
+ " if (gimple_call_num_args (_c%d) == %d)\n",
+ depth, e->ops.length ());
+ fprintf_indent (f, indent, " {\n");
fns[i]->gen (f, indent + 6, true, depth);
- fprintf_indent (f, indent,
- " }\n"
- " break;\n");
+ fprintf_indent (f, indent, " }\n");
+ fprintf_indent (f, indent, " break;\n");
}
fprintf_indent (f, indent, "default:;\n");
@@ -3278,6 +3282,11 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
}
}
+ static unsigned fail_label_cnt;
+ char local_fail_label[256];
+ snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_cnt);
+ fail_label = local_fail_label;
+
/* Analyze captures and perform early-outs on the incoming arguments
that cover cases we cannot handle. */
capture_info cinfo (s, result, gimple);
@@ -3289,8 +3298,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
if (cinfo.force_no_side_effects & (1 << i))
{
fprintf_indent (f, indent,
- "if (TREE_SIDE_EFFECTS (_p%d)) return NULL_TREE;\n",
- i);
+ "if (TREE_SIDE_EFFECTS (_p%d)) goto %s;\n",
+ i, fail_label);
if (verbose >= 1)
warning_at (as_a <expr *> (s->match)->ops[i]->location,
"forcing toplevel operand to have no "
@@ -3305,7 +3314,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
{
fprintf_indent (f, indent,
"if (TREE_SIDE_EFFECTS (captures[%d])) "
- "return NULL_TREE;\n", i);
+ "goto %s;\n", i, fail_label);
if (verbose >= 1)
warning_at (cinfo.info[i].c->location,
"forcing captured operand to have no "
@@ -3348,8 +3357,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
}
if (s->kind == simplify::SIMPLIFY)
- fprintf_indent (f, indent, "if (__builtin_expect (!dbg_cnt (match), 0)) return %s;\n",
- gimple ? "false" : "NULL_TREE");
+ fprintf_indent (f, indent, "if (__builtin_expect (!dbg_cnt (match), 0)) goto %s;\n", fail_label);
fprintf_indent (f, indent, "if (__builtin_expect (dump_file && (dump_flags & TDF_FOLDING), 0)) "
"fprintf (dump_file, \"%s ",
@@ -3361,6 +3369,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
true);
fprintf (f, ", __FILE__, __LINE__);\n");
+ fprintf_indent (f, indent, "{\n");
+ indent += 2;
if (!result)
{
/* If there is no result then this is a predicate implementation. */
@@ -3474,7 +3484,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
> cinfo.info[i].match_use_count)
fprintf_indent (f, indent,
"if (! tree_invariant_p (captures[%d])) "
- "return NULL_TREE;\n", i);
+ "goto %s;\n", i, fail_label);
}
for (unsigned j = 0; j < e->ops.length (); ++j)
{
@@ -3524,7 +3534,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
if (!is_a <operator_id *> (opr))
{
fprintf_indent (f, indent, "if (!_r)\n");
- fprintf_indent (f, indent, " return NULL_TREE;\n");
+ fprintf_indent (f, indent, " goto %s;\n", fail_label);
}
}
}
@@ -3563,6 +3573,10 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
fprintf_indent (f, indent, "return _r;\n");
}
}
+ indent -= 2;
+ fprintf_indent (f, indent, "}\n");
+ fprintf (f, "%s:;\n", fail_label);
+ fail_label = NULL;
}
/* Generate code for the '(if ...)', '(with ..)' and actual transform
--
2.27.0

View File

@ -0,0 +1,184 @@
From 6975b6e27ea6231d41c24afc51c77e0576b28b14 Mon Sep 17 00:00:00 2001
From: Marc Glisse <marc.glisse@inria.fr>
Date: Wed, 5 Aug 2020 16:45:33 +0200
Subject: [PATCH 15/26] VEC_COND_EXPR optimizations
When vector comparisons were forced to use vec_cond_expr, we lost a number of optimizations (my fault for not adding enough testcases to
prevent that). This patch tries to unwrap vec_cond_expr a bit so some optimizations can still happen.
I wasn't planning to add all those transformations together, but adding one caused a regression, whose fix introduced a second regression,
etc.
Restricting to constant folding would not be sufficient, we also need at least things like X|0 or X&X. The transformations are quite
conservative with :s and folding only if everything simplifies, we may want to relax this later. And of course we are going to miss things
like a?b:c + a?c:b -> b+c.
In terms of number of operations, some transformations turning 2 VEC_COND_EXPR into VEC_COND_EXPR + BIT_IOR_EXPR + BIT_NOT_EXPR might not look
like a gain... I expect the bit_not disappears in most cases, and VEC_COND_EXPR looks more costly than a simpler BIT_IOR_EXPR.
2020-08-05 Marc Glisse <marc.glisse@inria.fr>
PR tree-optimization/95906
PR target/70314
* match.pd ((c ? a : b) op d, (c ? a : b) op (c ? d : e),
(v ? w : 0) ? a : b, c1 ? c2 ? a : b : b): New transformations.
(op (c ? a : b)): Update to match the new transformations.
* gcc.dg/tree-ssa/andnot-2.c: New file.
* gcc.dg/tree-ssa/pr95906.c: Likewise.
* gcc.target/i386/pr70314.c: Likewise.
Reference commit in GCC: 229752afe3156a3990dacaedb94c76846cebf132
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/match.pd | 70 ++++++++++++++++++++----
gcc/testsuite/gcc.dg/tree-ssa/andnot-2.c | 10 ++++
gcc/testsuite/gcc.dg/tree-ssa/pr95906.c | 13 +++++
gcc/testsuite/gcc.target/i386/pr70314.c | 15 +++++
4 files changed, 96 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnot-2.c
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr95906.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr70314.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 01f81b063..25575af21 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3319,20 +3319,66 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (integer_zerop (@0))
@2)))
-/* Sink unary operations to constant branches, but only if we do fold it to
- constants. */
+#if GIMPLE
+/* Sink unary operations to branches, but only if we do fold both. */
(for op (negate bit_not abs absu)
(simplify
- (op (vec_cond @0 VECTOR_CST@1 VECTOR_CST@2))
- (with
- {
- tree cst1, cst2;
- cst1 = const_unop (op, type, @1);
- if (cst1)
- cst2 = const_unop (op, type, @2);
- }
- (if (cst1 && cst2)
- (vec_cond @0 { cst1; } { cst2; })))))
+ (op (vec_cond:s @0 @1 @2))
+ (vec_cond @0 (op! @1) (op! @2))))
+
+/* Sink binary operation to branches, but only if we can fold it. */
+(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
+ rdiv trunc_div ceil_div floor_div round_div
+ trunc_mod ceil_mod floor_mod round_mod min max)
+/* (c ? a : b) op (c ? d : e) --> c ? (a op d) : (b op e) */
+ (simplify
+ (op (vec_cond:s @0 @1 @2) (vec_cond:s @0 @3 @4))
+ (vec_cond @0 (op! @1 @3) (op! @2 @4)))
+
+/* (c ? a : b) op d --> c ? (a op d) : (b op d) */
+ (simplify
+ (op (vec_cond:s @0 @1 @2) @3)
+ (vec_cond @0 (op! @1 @3) (op! @2 @3)))
+ (simplify
+ (op @3 (vec_cond:s @0 @1 @2))
+ (vec_cond @0 (op! @3 @1) (op! @3 @2))))
+#endif
+
+/* (v ? w : 0) ? a : b is just (v & w) ? a : b */
+(simplify
+ (vec_cond (vec_cond:s @0 @3 integer_zerop) @1 @2)
+ (if (types_match (@0, @3))
+ (vec_cond (bit_and @0 @3) @1 @2)))
+(simplify
+ (vec_cond (vec_cond:s @0 integer_all_onesp @3) @1 @2)
+ (if (types_match (@0, @3))
+ (vec_cond (bit_ior @0 @3) @1 @2)))
+(simplify
+ (vec_cond (vec_cond:s @0 integer_zerop @3) @1 @2)
+ (if (types_match (@0, @3))
+ (vec_cond (bit_ior @0 (bit_not @3)) @2 @1)))
+(simplify
+ (vec_cond (vec_cond:s @0 @3 integer_all_onesp) @1 @2)
+ (if (types_match (@0, @3))
+ (vec_cond (bit_and @0 (bit_not @3)) @2 @1)))
+
+/* c1 ? c2 ? a : b : b --> (c1 & c2) ? a : b */
+(simplify
+ (vec_cond @0 (vec_cond:s @1 @2 @3) @3)
+ (if (types_match (@0, @1))
+ (vec_cond (bit_and @0 @1) @2 @3)))
+(simplify
+ (vec_cond @0 @2 (vec_cond:s @1 @2 @3))
+ (if (types_match (@0, @1))
+ (vec_cond (bit_ior @0 @1) @2 @3)))
+(simplify
+ (vec_cond @0 (vec_cond:s @1 @2 @3) @2)
+ (if (types_match (@0, @1))
+ (vec_cond (bit_ior (bit_not @0) @1) @2 @3)))
+(simplify
+ (vec_cond @0 @3 (vec_cond:s @1 @2 @3))
+ (if (types_match (@0, @1))
+ (vec_cond (bit_and (bit_not @0) @1) @2 @3)))
/* A few simplifications of "a ? CST1 : CST2". */
/* NOTE: Only do this on gimple as the if-chain-to-switch
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnot-2.c b/gcc/testsuite/gcc.dg/tree-ssa/andnot-2.c
new file mode 100644
index 000000000..e0955ce3f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/andnot-2.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop3-raw -w -Wno-psabi" } */
+
+typedef long vec __attribute__((vector_size(16)));
+vec f(vec x){
+ vec y = x < 10;
+ return y & (y == 0);
+}
+
+/* { dg-final { scan-tree-dump-not "_expr" "forwprop3" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr95906.c b/gcc/testsuite/gcc.dg/tree-ssa/pr95906.c
new file mode 100644
index 000000000..3d820a58e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr95906.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop3-raw -w -Wno-psabi" } */
+
+// FIXME: this should further optimize to a MAX_EXPR
+typedef signed char v16i8 __attribute__((vector_size(16)));
+v16i8 f(v16i8 a, v16i8 b)
+{
+ v16i8 cmp = (a > b);
+ return (cmp & a) | (~cmp & b);
+}
+
+/* { dg-final { scan-tree-dump-not "bit_(and|ior)_expr" "forwprop3" } } */
+/* { dg-final { scan-tree-dump-times "vec_cond_expr" 1 "forwprop3" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr70314.c b/gcc/testsuite/gcc.target/i386/pr70314.c
new file mode 100644
index 000000000..aad8dd9b5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr70314.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-march=skylake-avx512 -O2" } */
+/* { dg-final { scan-assembler-times "cmp" 2 } } */
+/* { dg-final { scan-assembler-not "and" } } */
+
+typedef long vec __attribute__((vector_size(16)));
+vec f(vec x, vec y){
+ return (x < 5) & (y < 8);
+}
+
+/* On x86_64, currently
+ vpcmpq $2, .LC1(%rip), %xmm1, %k1
+ vpcmpq $2, .LC0(%rip), %xmm0, %k0{%k1}
+ vpmovm2q %k0, %xmm0
+*/
--
2.27.0

View File

@ -0,0 +1,48 @@
From 77d1b4bd1b72be3769b2544f7f1e4a390fbf8e60 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Tue, 17 Nov 2020 12:02:50 +0000
Subject: [PATCH 16/26] aarch64: Remove XFAILs for two SVE tests
These tests started passing a while ago, so remove the XFAILs.
gcc/testsuite/
* gcc.target/aarch64/sve/cond_cnot_1.c: Remove XFAIL.
* gcc.target/aarch64/sve/cond_unary_1.c: Likewise.
Reference commit in GCC: 0f6759240f1df4240483d0ac3744ac60e82e702f
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_1.c | 5 ++---
gcc/testsuite/gcc.target/aarch64/sve/cond_unary_1.c | 6 ++----
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_1.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_1.c
index f587da1fb..49f0b18a5 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_1.c
@@ -30,6 +30,5 @@ TEST_ALL (DEF_LOOP)
/* { dg-final { scan-assembler-times {\tcnot\tz[0-9]+\.d, p[0-7]/m,} 2 } } */
/* { dg-final { scan-assembler-not {\tmov\tz} } } */
-/* { dg-final { scan-assembler-not {\tmovprfx\t} { xfail *-*-* } } } */
-/* Currently we canonicalize the ?: so that !b[i] is the "false" value. */
-/* { dg-final { scan-assembler-not {\tsel\t} { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-not {\tmovprfx\t} } } */
+/* { dg-final { scan-assembler-not {\tsel\t} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_1.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_1.c
index addedfa28..049247671 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_1.c
@@ -53,7 +53,5 @@ TEST_ALL (DEF_LOOP)
/* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
/* { dg-final { scan-assembler-not {\tmov\tz} } } */
-/* { dg-final { scan-assembler-not {\tmovprfx\t} { xfail *-*-* } } } */
-/* XFAILed because the ?: gets canonicalized so that the operation is in
- the false arm. */
-/* { dg-final { scan-assembler-not {\tsel\t} { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-not {\tmovprfx\t} } } */
+/* { dg-final { scan-assembler-not {\tsel\t} } } */
--
2.27.0

View File

@ -0,0 +1,39 @@
From a5f67f524a04353cc67d52c4b333a8e58ebcdd54 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Wed, 10 Mar 2021 17:40:25 +0100
Subject: [PATCH 17/26] testsuite: Fix up pr99305.C test on unsigned_char
targets [PR99498]
On unsigned_char targets, the cast stmt to unsigned char is obviously
not needed (and shouldn't be there). But it doesn't hurt to test
the rest also on targets where char is unsigned.
2021-03-10 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/99305
PR testsuite/99498
* g++.dg/opt/pr99305.C: Don't expect cast to unsigned char on
unsigned_char effective targets.
Reference commit in GCC: 5bf998275aff311b9804c1de944a88c219f35db6
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/testsuite/g++.dg/opt/pr99305.C | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/testsuite/g++.dg/opt/pr99305.C b/gcc/testsuite/g++.dg/opt/pr99305.C
index 8a91277e7..6fcdef391 100644
--- a/gcc/testsuite/g++.dg/opt/pr99305.C
+++ b/gcc/testsuite/g++.dg/opt/pr99305.C
@@ -1,7 +1,7 @@
// PR tree-optimization/99305
// { dg-do compile }
// { dg-options "-O3 -fno-ipa-icf -fdump-tree-optimized" }
-// { dg-final { scan-tree-dump-times " = \\\(unsigned char\\\) c_\[0-9]*\\\(D\\\);" 3 "optimized" } }
+// { dg-final { scan-tree-dump-times " = \\\(unsigned char\\\) c_\[0-9]*\\\(D\\\);" 3 "optimized" { target { ! unsigned_char } } } }
// { dg-final { scan-tree-dump-times " = \[^\n\r]* \\+ \[0-9]*;" 3 "optimized" } }
// { dg-final { scan-tree-dump-times " = \[^\n\r]* <= 9;" 3 "optimized" } }
// { dg-final { scan-tree-dump-not "if \\\(c_\[0-9]*\\\(D\\\) \[!=]= 0\\\)" "optimized" } }
--
2.27.0

View File

@ -0,0 +1,43 @@
From b00022c926d5de1f2e3c67e9e80232b1a9399abe Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Thu, 8 Apr 2021 17:39:11 +0100
Subject: [PATCH 18/26] match.pd: Fix sve/vcond_3.c
The sve/vcond_3.c tests had started to fail after PR97690/99305,
because we were generating:
a = VEC_COND_EXPR <cond, { 0, ... }, { 1, ... }>;
b = a << 15;
instead of:
a = VEC_COND_EXPR <cond, { 0, ... }, { 1<<15, ... }>;
We already have a match.pd rule to handle this kind of thing,
but it didn't handle shifts.
gcc/
* match.pd: Extend vec_cond folds to handle shifts.
Reference commit in GCC: 5240c5ca2e2b1f362670791df233c4103d87cf5b
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/match.pd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 25575af21..9d9627fe7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3328,7 +3328,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Sink binary operation to branches, but only if we can fold it. */
(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
- rdiv trunc_div ceil_div floor_div round_div
+ lshift rshift rdiv trunc_div ceil_div floor_div round_div
trunc_mod ceil_mod floor_mod round_mod min max)
/* (c ? a : b) op (c ? d : e) --> c ? (a op d) : (b op e) */
(simplify
--
2.27.0

View File

@ -0,0 +1,65 @@
From 6995a2f35d0f866068beddae33a8a0e9187861fd Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Sat, 5 Jun 2021 21:25:58 -0700
Subject: [PATCH 19/26] Fix PR 100925: Limit some a?CST1:CST2 optimizations to
intergal types only
The problem here is with offset (and pointer) types is we produce
a negative expression when this optimization hits.
It is easier to disable this optimization for all non-integeral types
instead of finding an integer type which is the same precission as the
type to do the negative expression on it.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
PR tree-optimization/100925
* match.pd (a ? CST1 : CST2): Limit transformations
that would produce a negative to integeral types only.
Change !POINTER_TYPE_P to INTEGRAL_TYPE_P also.
gcc/testsuite/ChangeLog:
* g++.dg/torture/pr100925.C: New test.
Reference commit in GCC: d4faa36e7540c573c5dc17850bcd938d0900b2e9
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/testsuite/g++.dg/torture/pr100925.C | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/torture/pr100925.C
diff --git a/gcc/testsuite/g++.dg/torture/pr100925.C b/gcc/testsuite/g++.dg/torture/pr100925.C
new file mode 100644
index 000000000..de13950dc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr100925.C
@@ -0,0 +1,24 @@
+// { dg-do compile }
+
+struct QScopedPointerDeleter {
+ static void cleanup(int *);
+};
+class QScopedPointer {
+ typedef int *QScopedPointer::*RestrictedBool;
+
+public:
+ operator RestrictedBool() { return d ? nullptr : &QScopedPointer::d; }
+ void reset() {
+ if (d)
+ QScopedPointerDeleter::cleanup(d);
+ }
+ int *d;
+};
+class DOpenGLPaintDevicePrivate {
+public:
+ QScopedPointer fbo;
+} DOpenGLPaintDeviceresize_d;
+void DOpenGLPaintDeviceresize() {
+ if (DOpenGLPaintDeviceresize_d.fbo)
+ DOpenGLPaintDeviceresize_d.fbo.reset();
+}
--
2.27.0

View File

@ -0,0 +1,94 @@
From 9c3b4e0b5690df62ca5e0c65a73bbccad017be24 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Sun, 10 Oct 2021 01:28:59 +0000
Subject: [PATCH 20/26] tree-optimization: [PR102622]: wrong code due to signed
one bit integer and "a?-1:0"
So it turns out this is kinda of a latent bug but not really latent.
In GCC 9 and 10, phi-opt would transform a?-1:0 (even for signed 1-bit integer)
to -(type)a but the type is an one bit integer which means the negation is
undefined. GCC 11 fixed the problem by checking for a?pow2cst:0 transformation
before a?-1:0 transformation.
When I added the transformations to match.pd, I had swapped the order not paying
attention and I didn't expect anything of it. Because there was no testcase failing
due to this.
Anyways this fixes the problem on the trunk by swapping the order in match.pd and
adding a comment of why the order is this way.
I will try to come up with a patch for GCC 9 and 10 series later on which fixes
the problem there too.
Note I didn't include the original testcase which requires the vectorizer and AVX-512f
as I can't figure out the right dg options to restrict it to avx-512f but I did come up
with a testcase which shows the problem and even more shows the problem with the 9/10
series as mentioned.
OK? Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/102622
gcc/ChangeLog:
* match.pd: Swap the order of a?pow2cst:0 and a?-1:0 transformations.
Swap the order of a?0:pow2cst and a?0:-1 transformations.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/bitfld-10.c: New test.
Reference commit in GCC: 882d806c1a8f9d2d2ade1133de88d63e5d4fe40c
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/match.pd | 3 ++-
.../gcc.c-torture/execute/bitfld-10.c | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.c-torture/execute/bitfld-10.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 9d9627fe7..d7d0dd0f7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3412,7 +3412,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (integer_onep (@2))
(convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
/* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
- (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
+ (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)
+ && TYPE_PRECISION (type) != 1)
(with {
tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
}
diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c
new file mode 100644
index 000000000..bdbf5733c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c
@@ -0,0 +1,24 @@
+/* PR tree-optimization/102622 */
+/* Wrong code introduced due to phi-opt
+ introducing undefined signed interger overflow
+ with one bit signed integer negation. */
+
+struct f{signed t:1;};
+int g(struct f *a, int t) __attribute__((noipa));
+int g(struct f *a, int t)
+{
+ if (t)
+ a->t = -1;
+ else
+ a->t = 0;
+ int t1 = a->t;
+ if (t1) return 1;
+ return t1;
+}
+
+int main(void)
+{
+ struct f a;
+ if (!g(&a, 1)) __builtin_abort();
+ return 0;
+}
--
2.27.0

View File

@ -0,0 +1,66 @@
From 3293cd744508b1d6d5079294858289676680b178 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Tue, 9 Nov 2021 09:56:10 +0000
Subject: [PATCH 21/26] Fix tree-optimization/103152: Still one more
-signed1bit issue
When I fixed PR 102622, I accidently left behind a TYPE_PRECISION
check which I had there for checking before hand. This check
is not needed as the code will handle it correctly anyways.
Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
PR tree-optimization/10352
gcc/ChangeLog:
* match.pd: Remove check of TYPE_PRECISION for
the a?0:pow2 case.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr10352-1.c: New test.
Reference commit in GCC: f7844b6a777cb47fec7208d7bd594f6ce66f1daa
Signed-off-by: Pronin Alexander 00812787 <pronin.alexander@huawei.com>
---
gcc/match.pd | 3 +--
gcc/testsuite/gcc.c-torture/execute/pr10352-1.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr10352-1.c
diff --git a/gcc/match.pd b/gcc/match.pd
index d7d0dd0f7..9d9627fe7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3412,8 +3412,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (integer_onep (@2))
(convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
/* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
- (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)
- && TYPE_PRECISION (type) != 1)
+ (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
(with {
tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr10352-1.c b/gcc/testsuite/gcc.c-torture/execute/pr10352-1.c
new file mode 100644
index 000000000..babb9d45a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr10352-1.c
@@ -0,0 +1,12 @@
+/* this is another case where phiopt
+ would create -signed1bit which is undefined. */
+struct {
+ int a:1;
+} b;
+int *c = (int *)&b, d;
+int main() {
+ d = c && (b.a = (d < 0) ^ 3);
+ if (d != 1)
+ __builtin_abort();
+ return 0;
+}
--
2.27.0

View File

@ -0,0 +1,117 @@
From 25d74b98caeaae881e374924886ee664aa1af5bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=83=91=E6=99=A8=E5=8D=89?= <zhengchenhui1@huawei.com>
Date: Mon, 9 Oct 2023 14:41:01 +0800
Subject: [PATCH 22/26] [DFE]Fix unexpected struct function pointer elimination
bug.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 9 ++-
gcc/testsuite/gcc.dg/struct/dfe_func_ptr.c | 69 ++++++++++++++++++++++
2 files changed, 76 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/struct/dfe_func_ptr.c
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 367bcf210..fe99e8733 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -438,7 +438,11 @@ srtype::has_dead_field (void)
unsigned i;
FOR_EACH_VEC_ELT (fields, i, this_field)
{
- if (!(this_field->field_access & READ_FIELD))
+ /* Function pointer members are not processed, because DFE
+ does not currently support accurate analysis of function
+ pointers, and we have not identified specific use cases. */
+ if (!(this_field->field_access & READ_FIELD)
+ && !FUNCTION_POINTER_TYPE_P (this_field->fieldtype))
{
may_dfe = true;
break;
@@ -1024,7 +1028,8 @@ srtype::create_new_type (void)
{
srfield *f = fields[i];
if (current_layout_opt_level & DEAD_FIELD_ELIMINATION
- && !(f->field_access & READ_FIELD))
+ && !(f->field_access & READ_FIELD)
+ && !FUNCTION_POINTER_TYPE_P (f->fieldtype))
continue;
f->create_new_fields (newtype, newfields, newlast);
}
diff --git a/gcc/testsuite/gcc.dg/struct/dfe_func_ptr.c b/gcc/testsuite/gcc.dg/struct/dfe_func_ptr.c
new file mode 100644
index 000000000..74ea93bbc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/struct/dfe_func_ptr.c
@@ -0,0 +1,69 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef STACK_SIZE
+#if STACK_SIZE > 16000
+#define N 1000
+#else
+#define N (STACK_SIZE/16)
+#endif
+#else
+#define N 1000
+#endif
+
+int num;
+
+int (*foo)(int d);
+int f (int t);
+
+typedef struct str_t str_t1;
+struct str_t
+{
+ int a;
+ float b;
+ int (*foo)(int d);
+};
+
+int main ()
+{
+ int i, r;
+ r = rand ();
+ num = r > N ? N : r;
+ str_t1 * p1 = calloc (num, sizeof (str_t1));
+ if (p1 == NULL)
+ return 0;
+ for (i = 0; i < num; i++)
+ {
+ p1[i].foo = malloc (1 * sizeof (f));
+ p1[i].foo = f;
+ p1[i].foo (i);
+ }
+
+ for (i = 0; i < num; i++)
+ p1[i].a = 1;
+
+ for (i = 0; i < num; i++)
+ p1[i].b = 2;
+
+ for (i = 0; i < num; i++)
+ if (p1[i].a != 1)
+ abort ();
+
+ for (i = 0; i < num; i++)
+ if (abs (p1[i].b - 2) > 0.0001)
+ abort ();
+
+ return 0;
+}
+
+int f (int t)
+{
+ if ( t < 0)
+ abort ();
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-times "Dead field elimination" 0 "struct_reorg" } } */
--
2.27.0

View File

@ -0,0 +1,25 @@
From bba233a851a49928f55deeb5e00cf5905abb79c0 Mon Sep 17 00:00:00 2001
From: Yarovoy Danil WX1195294 <yarovoy.danil@huawei-partners.com>
Date: Fri, 11 Nov 2022 17:48:39 +0300
Subject: [PATCH 23/26] Fix ICE bugs in transpose test cases with vector
indexing. Expand the result_chain size to fix the out of bounds issue.
---
gcc/tree-vect-data-refs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index e4466a4f3..b20e12513 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -5623,6 +5623,7 @@ vect_transpose_store_chain (vec<tree> dr_chain, unsigned int length,
...}> */
vect_indices_encoding (vectype, array_num, perm_mask_high, perm_mask_low);
+ result_chain->quick_grow (length);
for (unsigned int perm_time = 0; perm_time < log_length; perm_time++)
{
for (unsigned int index = 0; index < length / 2; index++)
--
2.27.0

View File

@ -0,0 +1,276 @@
From 0d3d9196da03be8e30ec799ee9ed8d577a2cf86e Mon Sep 17 00:00:00 2001
From: Diachkov Ilia WX1215920 <diachkov.ilia1@huawei-partners.com>
Date: Sat, 26 Nov 2022 02:25:24 +0300
Subject: [PATCH 24/26] Fix errors on testsuite c/c++ tests and 505.mcf_r
- add missed stmt check in decompress_candidate_without_check,
- generate missed converts and do not emit duplicate assignments,
- fix code indentation and line length.
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 130 +++++++++++++++---------
1 file changed, 81 insertions(+), 49 deletions(-)
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 367bcf210..068678b15 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -1543,7 +1543,7 @@ public:
bool check_sr_copy (gimple *);
void relayout_field_copy (gimple_stmt_iterator *, gimple *, tree, tree,
tree&, tree &);
- void do_semi_relayout (gimple_stmt_iterator *, gimple *, tree &, tree &);
+ bool do_semi_relayout (gimple_stmt_iterator *, gimple *, tree &, tree &);
};
struct ipa_struct_relayout
@@ -6481,7 +6481,10 @@ ipa_struct_reorg::pc_type_conversion_candidate_p (tree xhs)
if (TREE_CODE (xhs) == COMPONENT_REF)
{
- srtype *base_type = find_type (TREE_TYPE (TREE_OPERAND (xhs, 0)));
+ tree mem = TREE_OPERAND (xhs, 0);
+ if (TREE_CODE (mem) != MEM_REF)
+ return false;
+ srtype *base_type = find_type (TREE_TYPE (mem));
if (base_type != NULL && base_type->has_escaped ())
return pc_candidate_st_type_p (TREE_TYPE (xhs));
@@ -6795,7 +6798,8 @@ ipa_struct_reorg::decompress_candidate_without_check (gimple_stmt_iterator *gsi,
{
gsi_next (gsi);
gimple *next_stmt = gsi_stmt (*gsi);
- if (gimple_assign_rhs_class (next_stmt) == GIMPLE_SINGLE_RHS)
+ if (gimple_code (next_stmt) == GIMPLE_ASSIGN
+ && gimple_assign_rhs_class (next_stmt) == GIMPLE_SINGLE_RHS)
{
tree next_rhs = gimple_assign_rhs1 (next_stmt);
/* If current lhs is used as rhs in the next stmt:
@@ -6977,14 +6981,23 @@ ipa_struct_reorg::try_rewrite_with_pointer_compression (gassign *stmt,
if (pc_type_conversion_candidate_p (lhs))
{
/* Transfer MEM[(struct *)_1].files = _4;
- to MEM[(struct *)_1].files = (struct *)_4; */
- new_rhs = fold_convert (TREE_TYPE (lhs), tmp_rhs);
+ to _tmp = (struct *)_4;
+ MEM[(struct *)_1].files = _tmp; */
+ tree tmp_reg = create_tmp_reg(TREE_TYPE(lhs));
+ tree tmp_rhs_cvt = fold_convert (TREE_TYPE (lhs), tmp_rhs);
+ gimple *copy_stmt = gimple_build_assign (tmp_reg, tmp_rhs_cvt);
+ gsi_insert_before (gsi, copy_stmt, GSI_SAME_STMT);
+ new_rhs = tmp_reg;
}
else if (pc_type_conversion_candidate_p (rhs))
{
/* Transfer _4 = MEM[(struct *)_1].nodes;
- to _4 = (new_struct *) MEM[(struct *)_1].nodes; */
- new_rhs = fold_convert (TREE_TYPE (new_lhs), tmp_rhs);
+ to _tmp = MEM[(struct *)_1].nodes;
+ _4 = (new_struct *) _tmp; */
+ tree tmp_reg = create_tmp_reg(TREE_TYPE(new_lhs));
+ gimple *copy_stmt = gimple_build_assign (tmp_reg, tmp_rhs);
+ gsi_insert_before (gsi, copy_stmt, GSI_SAME_STMT);
+ new_rhs = fold_convert (TREE_TYPE (new_lhs), tmp_reg);
}
}
else if (l && r)
@@ -7007,46 +7020,45 @@ ipa_struct_reorg::rewrite_pointer_diff (gimple_stmt_iterator *gsi, tree ptr1,
{
tree shifts = build_int_cst (long_integer_type_node, semi_relayout_align);
tree pointer_type = build_pointer_type (unsigned_char_type_node);
+ tree intptr_type = signed_type_for (pointer_type);
+
/* addr_high_1 = (intptr_t)ptr1 >> shifts */
- tree ptr1_cvt = fold_convert (pointer_type, ptr1);
- tree addr_high_1 = gimplify_build2 (gsi, RSHIFT_EXPR, pointer_type,
+ tree ptr1_cvt = fold_convert (intptr_type, ptr1);
+ tree addr_high_1 = gimplify_build2 (gsi, RSHIFT_EXPR, intptr_type,
ptr1_cvt, shifts);
/* addr_high_2 = (intptr_t)ptr2 >> shifts */
- tree ptr2_cvt = fold_convert (pointer_type, ptr2);
- tree addr_high_2 = gimplify_build2 (gsi, RSHIFT_EXPR, pointer_type,
+ tree ptr2_cvt = fold_convert (intptr_type, ptr2);
+ tree addr_high_2 = gimplify_build2 (gsi, RSHIFT_EXPR, intptr_type,
ptr2_cvt, shifts);
/* off1 = (intptr_t)ptr1 - (addr_high_1 << shifts) */
- tree bucket_start_1 = gimplify_build2 (gsi, LSHIFT_EXPR, pointer_type,
+ tree bucket_start_1 = gimplify_build2 (gsi, LSHIFT_EXPR, intptr_type,
addr_high_1, shifts);
- tree off1 = gimplify_build2 (gsi, MINUS_EXPR, long_integer_type_node,
+ tree off1 = gimplify_build2 (gsi, MINUS_EXPR, intptr_type,
ptr1_cvt, bucket_start_1);
/* off2 = (intptr_t)ptr2 - (addr_high_2 << shifts) */
- tree bucket_start_2 = gimplify_build2 (gsi, LSHIFT_EXPR, pointer_type,
+ tree bucket_start_2 = gimplify_build2 (gsi, LSHIFT_EXPR, intptr_type,
addr_high_2, shifts);
- tree off2 = gimplify_build2 (gsi, MINUS_EXPR, long_integer_type_node,
+ tree off2 = gimplify_build2 (gsi, MINUS_EXPR, intptr_type,
ptr2_cvt, bucket_start_2);
/* group_diff = (addr_high_1 - addr_high_2) / bucket_parts */
- tree bucket_sub = gimplify_build2 (gsi, MINUS_EXPR, long_integer_type_node,
+ tree bucket_sub = gimplify_build2 (gsi, MINUS_EXPR, intptr_type,
addr_high_1, addr_high_2);
- tree bucket_parts = build_int_cst (long_integer_type_node,
- type->bucket_parts);
- tree group_diff = gimplify_build2 (gsi, TRUNC_DIV_EXPR,
- long_integer_type_node,
+ tree bucket_parts = build_int_cst (intptr_type, type->bucket_parts);
+ tree group_diff = gimplify_build2 (gsi, TRUNC_DIV_EXPR, intptr_type,
bucket_sub, bucket_parts);
/* off_addr_diff = off1 - off2 */
- tree off_addr_diff = gimplify_build2 (gsi, MINUS_EXPR, long_integer_type_node,
+ tree off_addr_diff = gimplify_build2 (gsi, MINUS_EXPR, intptr_type,
off1, off2);
/* res = group_diff * bucket_capacity + off_diff / 8 */
+ /* TODO: add info about magic numbers relayout_part_size/8 and 8. */
tree capacity = build_int_cst (long_integer_type_node,
relayout_part_size / 8);
tree unit_size = build_int_cst (long_integer_type_node, 8);
- tree bucket_index_diff = gimplify_build2 (gsi, MULT_EXPR,
- long_integer_type_node,
+ tree bucket_index_diff = gimplify_build2 (gsi, MULT_EXPR, intptr_type,
group_diff, capacity);
- tree off_index = gimplify_build2 (gsi, TRUNC_DIV_EXPR,
- long_integer_type_node,
+ tree off_index = gimplify_build2 (gsi, TRUNC_DIV_EXPR, intptr_type,
off_addr_diff, unit_size);
- tree res = gimplify_build2 (gsi, PLUS_EXPR, long_unsigned_type_node,
+ tree res = gimplify_build2 (gsi, PLUS_EXPR, intptr_type,
bucket_index_diff, off_index);
return res;
}
@@ -7071,31 +7083,34 @@ basic_block
create_bb_for_group_diff_ne_0 (basic_block new_bb, tree &phi, tree ptr,
tree group_diff, tree off_times_8, srtype *type)
{
- tree shifts = build_int_cst (long_unsigned_type_node, semi_relayout_align);
+ tree intptr_type = signed_type_for (long_unsigned_type_node);
+ tree shifts = build_int_cst (intptr_type, semi_relayout_align);
gimple_stmt_iterator gsi = gsi_last_bb (new_bb);
gsi_insert_after (&gsi, gimple_build_nop (), GSI_NEW_STMT);
- /* curr_group_start = (ptr >> shifts) << shifts; */
- tree ptr_r_1 = gimplify_build2 (&gsi, RSHIFT_EXPR, long_integer_type_node,
- ptr, shifts);
- tree curr_group_start = gimplify_build2 (&gsi, LSHIFT_EXPR, long_integer_type_node,
+ tree ptr_cvt = fold_convert (intptr_type, ptr);
+ /* intptr_t curr_group_start = ((intptr_t) ptr >> shifts) << shifts; */
+ tree ptr_r_1 = gimplify_build2 (&gsi, RSHIFT_EXPR, intptr_type,
+ ptr_cvt, shifts);
+ tree curr_group_start = gimplify_build2 (&gsi, LSHIFT_EXPR, intptr_type,
ptr_r_1, shifts);
- /* curr_off_from_group = ptr - curr_group_start; */
- tree curr_off_from_group = gimplify_build2 (&gsi, MINUS_EXPR,
- long_integer_type_node,
- ptr, curr_group_start);
+ /* intptr_t curr_off_from_group = (intptr_t)ptr - curr_group_start; */
+ tree curr_off_from_group = gimplify_build2 (&gsi, MINUS_EXPR, intptr_type,
+ ptr_cvt, curr_group_start);
/* res = curr_group_start + ((group_diff * parts) << shifts)
+ ((curr_off_from_group + off_times_8) % shifts); */
tree step1 = gimplify_build2 (&gsi, MULT_EXPR, long_integer_type_node,
group_diff, build_int_cst (
long_integer_type_node, type->bucket_parts));
- tree step2 = gimplify_build2 (&gsi, LSHIFT_EXPR, long_integer_type_node,
- step1, shifts);
- tree step3 = gimplify_build2 (&gsi, PLUS_EXPR, long_integer_type_node,
- curr_off_from_group, off_times_8);
- tree step4 = gimplify_build2 (&gsi, TRUNC_MOD_EXPR, long_integer_type_node,
- step3, build_int_cst (
- long_integer_type_node, relayout_part_size));
- tree step5 = gimplify_build2 (&gsi, PLUS_EXPR, long_integer_type_node,
+ tree step1_cvt = fold_convert (intptr_type, step1);
+ tree step2 = gimplify_build2 (&gsi, LSHIFT_EXPR, intptr_type,
+ step1_cvt, shifts);
+ tree off_times_8_cvt = fold_convert (intptr_type, off_times_8);
+ tree step3 = gimplify_build2 (&gsi, PLUS_EXPR, intptr_type,
+ curr_off_from_group, off_times_8_cvt);
+ tree step4 = gimplify_build2 (&gsi, TRUNC_MOD_EXPR, intptr_type,
+ step3, build_int_cst (intptr_type,
+ relayout_part_size));
+ tree step5 = gimplify_build2 (&gsi, PLUS_EXPR, intptr_type,
step2, step4);
tree res_phi1 = gimplify_build2 (&gsi, PLUS_EXPR, long_integer_type_node,
curr_group_start, step5);
@@ -7350,14 +7365,22 @@ ipa_struct_reorg::relayout_field_copy (gimple_stmt_iterator *gsi, gimple *stmt,
continue;
new_l_mem_ref = rewrite_address (lhs_base_pointer, field, type, gsi);
new_r_mem_ref = rewrite_address (rhs_base_pointer, field, type, gsi);
+ if (!is_gimple_reg (new_l_mem_ref))
+ {
+ tree tmp_reg = create_tmp_reg(TREE_TYPE(new_l_mem_ref));
+ gimple *copy_stmt = gimple_build_assign (tmp_reg, new_r_mem_ref);
+ gsi_insert_before (gsi, copy_stmt, GSI_SAME_STMT);
+ new_r_mem_ref = tmp_reg;
+ }
gimple *new_stmt = gimple_build_assign (new_l_mem_ref, new_r_mem_ref);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
+ gcc_assert (new_l_mem_ref != NULL_TREE && new_r_mem_ref != NULL_TREE);
newlhs = new_l_mem_ref;
newrhs = new_r_mem_ref;
}
-void
+bool
ipa_struct_reorg::do_semi_relayout (gimple_stmt_iterator *gsi, gimple *stmt,
tree &newlhs, tree &newrhs)
{
@@ -7374,7 +7397,10 @@ ipa_struct_reorg::do_semi_relayout (gimple_stmt_iterator *gsi, gimple *stmt,
if (!l && !r)
{
if (check_sr_copy (stmt))
- relayout_field_copy (gsi, stmt, lhs, rhs, newlhs, newrhs);
+ {
+ relayout_field_copy (gsi, stmt, lhs, rhs, newlhs, newrhs);
+ return true;
+ }
}
else if (l)
{
@@ -7396,6 +7422,7 @@ ipa_struct_reorg::do_semi_relayout (gimple_stmt_iterator *gsi, gimple *stmt,
gsi, TREE_OPERAND (newrhs, 0), type);
newrhs = rewrite_address (pointer_base, new_field, type, gsi);
}
+ return false;
}
bool
@@ -7628,7 +7655,7 @@ ipa_struct_reorg::rewrite_assign (gassign *stmt, gimple_stmt_iterator *gsi)
if (dump_file && (dump_flags & TDF_DETAILS))
{
- fprintf (dump_file, "\nrewriting stamtenet:\n");
+ fprintf (dump_file, "\nrewriting statement:\n");
print_gimple_stmt (dump_file, stmt, 0);
}
tree newlhs[max_split];
@@ -7644,19 +7671,24 @@ ipa_struct_reorg::rewrite_assign (gassign *stmt, gimple_stmt_iterator *gsi)
fprintf (dump_file, "replaced with:\n");
for (unsigned i = 0; i < max_split && (newlhs[i] || newrhs[i]); i++)
{
+ bool fields_copied = false;
if (current_layout_opt_level & SEMI_RELAYOUT)
- do_semi_relayout (gsi, stmt, newlhs[i], newrhs[i]);
+ fields_copied = do_semi_relayout (gsi, stmt, newlhs[i], newrhs[i]);
if (current_layout_opt_level >= POINTER_COMPRESSION_SAFE)
try_rewrite_with_pointer_compression (stmt, gsi, lhs, rhs,
newlhs[i], newrhs[i]);
- gimple *newstmt = gimple_build_assign (newlhs[i] ? newlhs[i] : lhs, newrhs[i] ? newrhs[i] : rhs);
+ remove = true;
+ if (fields_copied)
+ continue;
+ tree lhs_expr = newlhs[i] ? newlhs[i] : lhs;
+ tree rhs_expr = newrhs[i] ? newrhs[i] : rhs;
+ gimple *newstmt = gimple_build_assign (lhs_expr, rhs_expr);
if (dump_file && (dump_flags & TDF_DETAILS))
{
print_gimple_stmt (dump_file, newstmt, 0);
fprintf (dump_file, "\n");
}
gsi_insert_before (gsi, newstmt, GSI_SAME_STMT);
- remove = true;
}
return remove;
}
--
2.27.0

View File

@ -0,0 +1,53 @@
From 0f6bfc8b3b95065927fc26fb1bb20afb9672e744 Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Thu, 8 Dec 2022 04:36:01 +0800
Subject: [PATCH 25/26] Fix an error in memory allocation/deallocation
---
gcc/symbol-summary.h | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/gcc/symbol-summary.h b/gcc/symbol-summary.h
index 1e7341b24..2f7b1a348 100644
--- a/gcc/symbol-summary.h
+++ b/gcc/symbol-summary.h
@@ -59,15 +59,15 @@ protected:
/* Allocates new data that are stored within map. */
T* allocate_new ()
{
- /* In structure optimizatons, we call new to ensure that
- the allocated memory is initialized to 0. */
- if (flag_ipa_struct_reorg)
- return is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T ()
- : new T ();
/* Call gcc_internal_because we do not want to call finalizer for
a type T. We call dtor explicitly. */
- return is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T ()
- : m_allocator.allocate () ;
+ T* allocated = is_ggc () ? new (ggc_internal_alloc (sizeof (T))) T ()
+ : m_allocator.allocate ();
+ /* In structure optimizatons, we call memset to ensure that
+ the allocated memory is initialized to 0. */
+ if (flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ memset (allocated, 0, sizeof (T));
+ return allocated;
}
/* Release an item that is stored within map. */
@@ -76,12 +76,7 @@ protected:
if (is_ggc ())
ggc_delete (item);
else
- {
- if (flag_ipa_struct_reorg)
- delete item;
- else
- m_allocator.remove (item);
- }
+ m_allocator.remove (item);
}
/* Unregister all call-graph hooks. */
--
2.27.0

View File

@ -0,0 +1,153 @@
From b5a3bfe92f96cd0d2224d80ac4eaa80dab1bd6bf Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Thu, 22 Dec 2022 16:10:46 +0800
Subject: [PATCH 26/26] Fix warnings and errors with debug prints
---
gcc/ipa-struct-reorg/ipa-struct-reorg.c | 37 +++++++++++++++----------
gcc/symbol-summary.h | 2 +-
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
index 068678b15..d87024df0 100644
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
@@ -1203,7 +1203,7 @@ srfunction::create_new_decls (void)
else if (TREE_CODE (decls[i]->decl) == PARM_DECL)
;
else
- internal_error ("Unhandled decl type stored");
+ internal_error ("Unhandled declaration type stored");
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -1759,7 +1759,8 @@ ipa_struct_relayout::rewrite (void)
}
bool
-ipa_struct_relayout::rewrite_debug (gimple *stmt, gimple_stmt_iterator *gsi)
+ipa_struct_relayout::rewrite_debug (gimple *stmt ATTRIBUTE_UNUSED,
+ gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED)
{
/* Delete debug gimple now. */
return true;
@@ -2079,7 +2080,6 @@ bool
ipa_struct_relayout::maybe_rewrite_cst (tree cst, gimple_stmt_iterator *gsi,
HOST_WIDE_INT &times)
{
- bool ret = false;
gcc_assert (TREE_CODE (cst) == INTEGER_CST);
gimple *stmt = gsi_stmt (*gsi);
@@ -7166,7 +7166,7 @@ create_bb_for_group_diff_ne_0 (basic_block new_bb, tree &phi, tree ptr,
}
tree
-ipa_struct_reorg::rewrite_pointer_plus_integer (gimple *stmt,
+ipa_struct_reorg::rewrite_pointer_plus_integer (gimple *stmt ATTRIBUTE_UNUSED,
gimple_stmt_iterator *gsi,
tree ptr, tree offset,
srtype *type)
@@ -7348,8 +7348,9 @@ ipa_struct_reorg::check_sr_copy (gimple *stmt)
}
void
-ipa_struct_reorg::relayout_field_copy (gimple_stmt_iterator *gsi, gimple *stmt,
- tree lhs, tree rhs,
+ipa_struct_reorg::relayout_field_copy (gimple_stmt_iterator *gsi,
+ gimple *stmt ATTRIBUTE_UNUSED,
+ tree lhs, tree rhs ATTRIBUTE_UNUSED,
tree &newlhs, tree &newrhs)
{
srtype *type = get_relayout_candidate_type (TREE_TYPE (lhs));
@@ -7724,8 +7725,6 @@ void
ipa_struct_reorg::record_allocated_size (tree ptr, gimple_stmt_iterator *gsi,
tree size)
{
- tree to_type = build_pointer_type (long_unsigned_type_node);
- tree type_cast = fold_convert (to_type, ptr);
tree lhs = fold_build2 (MEM_REF, long_unsigned_type_node, ptr,
build_int_cst (build_pointer_type (long_unsigned_type_node), 0));
gimple *stmt = gimple_build_assign (lhs, size);
@@ -8084,7 +8083,8 @@ ipa_struct_reorg::rewrite_call (gcall *stmt, gimple_stmt_iterator *gsi)
old statement is to be removed. */
bool
-ipa_struct_reorg::rewrite_cond (gcond *stmt, gimple_stmt_iterator *gsi)
+ipa_struct_reorg::rewrite_cond (gcond *stmt,
+ gimple_stmt_iterator *gsi ATTRIBUTE_UNUSED)
{
tree_code rhs_code = gimple_cond_code (stmt);
@@ -8328,6 +8328,8 @@ ipa_struct_reorg::rewrite_functions (void)
if (current_function_decl)
dump_function_to_file (current_function_decl, dump_file,
dump_flags | TDF_VOPS);
+ else
+ fprintf (dump_file, " no declaration\n");
}
pop_cfun ();
}
@@ -8360,11 +8362,13 @@ ipa_struct_reorg::rewrite_functions (void)
push_cfun (DECL_STRUCT_FUNCTION (node->decl));
if (dump_file && (dump_flags & TDF_DETAILS))
{
- fprintf (dump_file, "==== Before create decls: %dth_%s ====\n\n",
+ fprintf (dump_file, "==== Before create decls: %dth %s ====\n\n",
i, f->node->name ());
if (current_function_decl)
dump_function_to_file (current_function_decl, dump_file,
dump_flags | TDF_VOPS);
+ else
+ fprintf (dump_file, " no declaration\n");
}
pop_cfun ();
}
@@ -8396,11 +8400,13 @@ ipa_struct_reorg::rewrite_functions (void)
if (dump_file && (dump_flags & TDF_DETAILS))
{
- fprintf (dump_file, "\nBefore rewrite: %dth_%s\n",
+ fprintf (dump_file, "\nBefore rewrite: %dth %s\n",
i, f->node->name ());
if (current_function_decl)
dump_function_to_file (current_function_decl, dump_file,
dump_flags | TDF_VOPS);
+ else
+ fprintf (dump_file, " no declaration\n");
fprintf (dump_file, "\n======== Start to rewrite: %dth_%s ========\n",
i, f->node->name ());
}
@@ -8475,10 +8481,13 @@ ipa_struct_reorg::rewrite_functions (void)
if (dump_file)
{
- fprintf (dump_file, "\nAfter rewrite: %dth_%s\n",
+ fprintf (dump_file, "\nAfter rewrite: %dth %s\n",
i, f->node->name ());
- dump_function_to_file (current_function_decl, dump_file,
- dump_flags | TDF_VOPS);
+ if (current_function_decl)
+ dump_function_to_file (current_function_decl, dump_file,
+ dump_flags | TDF_VOPS);
+ else
+ fprintf (dump_file, " no declaration\n");
}
pop_cfun ();
diff --git a/gcc/symbol-summary.h b/gcc/symbol-summary.h
index 2f7b1a348..ce13eb340 100644
--- a/gcc/symbol-summary.h
+++ b/gcc/symbol-summary.h
@@ -65,7 +65,7 @@ protected:
: m_allocator.allocate ();
/* In structure optimizatons, we call memset to ensure that
the allocated memory is initialized to 0. */
- if (flag_ipa_struct_layout || flag_ipa_struct_reorg)
+ if (flag_ipa_struct_reorg)
memset (allocated, 0, sizeof (T));
return allocated;
}
--
2.27.0

View File

@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
Release: 38
Release: 39
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@ -230,6 +230,25 @@ Patch119: 0119-aarch64-Simplif-yprobe-of-final-frame-allocation.patch
Patch120: 0120-aarch64-Explicitly-record-probe-registers-in-frame-info.patch
Patch121: 0121-aarch64-Remove-below_hard_fp_saved_regs_size.patch
Patch122: 0122-aarch64-Make-stack-smash-canary-protect-saved-registers.patch
Patch123: 0123-DFE-Fix-internal-compiler-error-with-fipa-struct-reo.patch
Patch124: 0124-tree-vect-generic-Tweak-build_replicated_const-PR949.patch
Patch125: 0125-tree-vect-generic-Fix-bitfield-widths-PR94980-3-3.patch
Patch126: 0126-Lower-VEC_COND_EXPR-into-internal-functions.patch
Patch127: 0127-Add-missing-check-for-gassign.patch
Patch128: 0128-Amend-match.pd-syntax-with-force-simplified-results.patch
Patch129: 0129-Make-genmatch-transform-failure-handling-more-consis.patch
Patch130: 0130-VEC_COND_EXPR-optimizations.patch
Patch131: 0131-aarch64-Remove-XFAILs-for-two-SVE-tests.patch
Patch132: 0132-testsuite-Fix-up-pr99305.C-test-on-unsigned_char-tar.patch
Patch133: 0133-match.pd-Fix-sve-vcond_3.c.patch
Patch134: 0134-Fix-PR-100925-Limit-some-a-CST1-CST2-optimizations-t.patch
Patch135: 0135-tree-optimization-PR102622-wrong-code-due-to-signed-.patch
Patch136: 0136-Fix-tree-optimization-103152-Still-one-more-signed1b.patch
Patch137: 0137-DFE-Fix-unexpected-struct-function-pointer-eliminati.patch
Patch138: 0138-Fix-ICE-bugs-in-transpose-test-cases-with-vector-ind.patch
Patch139: 0139-Fix-errors-on-testsuite-c-c-tests-and-505.mcf_r.patch
Patch140: 0140-Fix-an-error-in-memory-allocation-deallocation.patch
Patch141: 0141-Fix-warnings-and-errors-with-debug-prints.patch
%global gcc_target_platform %{_arch}-linux-gnu
@ -805,6 +824,25 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch120 -p1
%patch121 -p1
%patch122 -p1
%patch123 -p1
%patch124 -p1
%patch125 -p1
%patch126 -p1
%patch127 -p1
%patch128 -p1
%patch129 -p1
%patch130 -p1
%patch131 -p1
%patch132 -p1
%patch133 -p1
%patch134 -p1
%patch135 -p1
%patch136 -p1
%patch137 -p1
%patch138 -p1
%patch139 -p1
%patch140 -p1
%patch141 -p1
%build
@ -2829,6 +2867,12 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Wed Nov 29 2023 Mingchuan Wu <wumingchuan1992@foxmail.com> - 10.3.1-39
- Type:Spec
- ID:NA
- SUG:NA
- DESC: Sync patch from openeuler/gcc
* Tue Oct 10 2023 Xiong Zhou <xiongzhou4@huawei.com> - 10.3.1-38
- Type:Backport
- ID:NA