[Sync] Sync patch from openeuler/gcc
Sync patch from openeuler/gcc - 20210914
This commit is contained in:
parent
9ed542c2bd
commit
0363047aa1
87
0023-StructReorderFields-Add-pointer-offset-check.patch
Normal file
87
0023-StructReorderFields-Add-pointer-offset-check.patch
Normal file
@ -0,0 +1,87 @@
|
||||
From 83a35da4910fc7d8f29ced3e0ff8adddeb537731 Mon Sep 17 00:00:00 2001
|
||||
From: huangxiaoquan <huangxiaoquan1@huawei.com>
|
||||
Date: Fri, 27 Aug 2021 14:53:18 +0800
|
||||
Subject: [PATCH 23/24] [StructReorderFields] Add pointer offset check
|
||||
|
||||
The pointer offset check is added for the expr that is dereferenced
|
||||
in the memory, and escapes struct pointer offset operations involving
|
||||
field order.
|
||||
|
||||
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
index 85986ce5803..b0d4fe80797 100644
|
||||
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
@@ -3876,6 +3876,17 @@ ipa_struct_reorg::get_type_field (tree expr, tree &base, bool &indirect,
|
||||
return false;
|
||||
}
|
||||
|
||||
+ /* Escape the operation of fetching field with pointer offset such as:
|
||||
+ *(&(t->right)) = malloc (0); -> MEM[(struct node * *)_1 + 8B] = malloc (0);
|
||||
+ */
|
||||
+ if (current_mode != NORMAL
|
||||
+ && (TREE_CODE (expr) == MEM_REF) && (offset != 0))
|
||||
+ {
|
||||
+ gcc_assert (can_escape);
|
||||
+ t->mark_escape (escape_non_multiply_size, NULL);
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
if (wholeaccess (expr, base, accesstype, t))
|
||||
{
|
||||
field = NULL;
|
||||
diff --git a/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c b/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
|
||||
index 190b9418275..2ae46fb3112 100644
|
||||
--- a/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
|
||||
+++ b/gcc/testsuite/gcc.dg/struct/rf_ptr2void_lto.c
|
||||
@@ -84,4 +84,4 @@ main ()
|
||||
return cnt;
|
||||
}
|
||||
|
||||
-/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "reorder_fields" } } */
|
||||
\ No newline at end of file
|
||||
+/* { dg-final { scan-ipa-dump "No structures to transform." "reorder_fields" } } */
|
||||
\ No newline at end of file
|
||||
diff --git a/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c b/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c
|
||||
new file mode 100644
|
||||
index 00000000000..317aafa5f72
|
||||
--- /dev/null
|
||||
+++ b/gcc/testsuite/gcc.dg/struct/rf_ptr_offset.c
|
||||
@@ -0,0 +1,34 @@
|
||||
+/* { dg-do compile } */
|
||||
+
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+struct node
|
||||
+{
|
||||
+ struct node *left, *right;
|
||||
+ double a, b, c, d, e, f;
|
||||
+}
|
||||
+*a;
|
||||
+int b, c;
|
||||
+void
|
||||
+CreateNode (struct node **p1)
|
||||
+{
|
||||
+ *p1 = calloc (10, sizeof (struct node));
|
||||
+}
|
||||
+
|
||||
+int
|
||||
+main ()
|
||||
+{
|
||||
+ a->left = 0;
|
||||
+ struct node *t = a;
|
||||
+ CreateNode (&t->right);
|
||||
+
|
||||
+ struct node p = *a;
|
||||
+ b = 1;
|
||||
+ if (p.left)
|
||||
+ b = 0;
|
||||
+ if (b)
|
||||
+ printf (" Tree.\n");
|
||||
+}
|
||||
+
|
||||
+/* { dg-final { scan-ipa-dump "No structures to transform." "reorder_fields" } } */
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.21.0.windows.1
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
From 0ee0f0ebeb098787cb9698887c237606b6ab10c6 Mon Sep 17 00:00:00 2001
|
||||
From: huangxiaoquan <huangxiaoquan1@huawei.com>
|
||||
Date: Wed, 1 Sep 2021 17:07:22 +0800
|
||||
Subject: [PATCH 24/24] [StructReorderFields] Add lto and whole-program gate
|
||||
|
||||
Only enable struct reorder fields optimizations in lto or whole-program.
|
||||
This prevents some .c files from being struct reorder fields optimized
|
||||
while some of them are not optimized during project compilation.
|
||||
|
||||
diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.c b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
index b0d4fe80797..2bf41e0d83b 100644
|
||||
--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
+++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.c
|
||||
@@ -6655,7 +6655,9 @@ pass_ipa_struct_reorg::gate (function *)
|
||||
&& flag_lto_partition == LTO_PARTITION_ONE
|
||||
/* Only enable struct optimizations in C since other
|
||||
languages' grammar forbid. */
|
||||
- && lang_c_p ());
|
||||
+ && lang_c_p ()
|
||||
+ /* Only enable struct optimizations in lto or whole_program. */
|
||||
+ && (in_lto_p || flag_whole_program));
|
||||
}
|
||||
|
||||
const pass_data pass_data_ipa_reorder_fields =
|
||||
@@ -6699,7 +6701,9 @@ pass_ipa_reorder_fields::gate (function *)
|
||||
&& flag_lto_partition == LTO_PARTITION_ONE
|
||||
/* Only enable struct optimizations in C since other
|
||||
languages' grammar forbid. */
|
||||
- && lang_c_p ());
|
||||
+ && lang_c_p ()
|
||||
+ /* Only enable struct optimizations in lto or whole_program. */
|
||||
+ && (in_lto_p || flag_whole_program));
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
diff --git a/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c b/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||||
index 6565fe8dd63..23444fe8b0d 100644
|
||||
--- a/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||||
+++ b/gcc/testsuite/gcc.dg/struct/struct_reorg-1.c
|
||||
@@ -1,5 +1,5 @@
|
||||
// { dg-do compile }
|
||||
-// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all" }
|
||||
+// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all -fwhole-program" }
|
||||
|
||||
struct a
|
||||
{
|
||||
@@ -21,4 +21,10 @@ int g(void)
|
||||
return b->t;
|
||||
}
|
||||
|
||||
+int main()
|
||||
+{
|
||||
+ f ();
|
||||
+ return g ();
|
||||
+}
|
||||
+
|
||||
/* { dg-final { scan-ipa-dump "No structures to transform." "struct_reorg" } } */
|
||||
diff --git a/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c b/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||||
index 5864ad46fd3..2d1f95c9935 100644
|
||||
--- a/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||||
+++ b/gcc/testsuite/gcc.dg/struct/struct_reorg-3.c
|
||||
@@ -1,5 +1,5 @@
|
||||
// { dg-do compile }
|
||||
-// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all" }
|
||||
+// { dg-options "-O3 -flto-partition=one -fipa-struct-reorg -fdump-ipa-all -fwhole-program" }
|
||||
|
||||
#include <stdlib.h>
|
||||
typedef struct {
|
||||
@@ -10,7 +10,7 @@ typedef struct {
|
||||
compile_stack_elt_t *stack;
|
||||
unsigned size;
|
||||
} compile_stack_type;
|
||||
-void f (const char *p, const char *pend, int c)
|
||||
+__attribute__((noinline)) void f (const char *p, const char *pend, int c)
|
||||
{
|
||||
compile_stack_type compile_stack;
|
||||
while (p != pend)
|
||||
@@ -20,4 +20,9 @@ void f (const char *p, const char *pend, int c)
|
||||
* sizeof (compile_stack_elt_t));
|
||||
}
|
||||
|
||||
+int main()
|
||||
+{
|
||||
+ f (NULL, NULL, 1);
|
||||
+}
|
||||
+
|
||||
/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "struct_reorg" } } */
|
||||
--
|
||||
2.21.0.windows.1
|
||||
|
||||
14
gcc.spec
14
gcc.spec
@ -1,4 +1,4 @@
|
||||
%global DATE 20210827
|
||||
%global DATE 20210914
|
||||
|
||||
%global gcc_version 10.3.1
|
||||
%global gcc_major 10.3.1
|
||||
@ -63,7 +63,7 @@
|
||||
Summary: Various compilers (C, C++, Objective-C, ...)
|
||||
Name: gcc
|
||||
Version: %{gcc_version}
|
||||
Release: %{DATE}.4
|
||||
Release: %{DATE}.5
|
||||
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
|
||||
URL: https://gcc.gnu.org
|
||||
|
||||
@ -140,6 +140,8 @@ Patch19: 0019-StructReorderFields-Fix-bugs-and-improve-mechanism.patch
|
||||
Patch20: 0020-Backport-vect-Fix-an-ICE-in-vect_recog_mask_conversi.patch
|
||||
Patch21: 0021-mcmodel-Bugfix-for-mcmodel-medium-on-x86.patch
|
||||
Patch22: 0022-StructReorderFields-Fix-pointer-layer-check-bug.patch
|
||||
Patch23: 0023-StructReorderFields-Add-pointer-offset-check.patch
|
||||
Patch24: 0024-StructReorderFields-Add-lto-and-whole-program-gate.patch
|
||||
|
||||
%global gcc_target_platform %{_arch}-linux-gnu
|
||||
|
||||
@ -603,6 +605,8 @@ not stable, so plugins must be rebuilt any time GCC is updated.
|
||||
%patch20 -p1
|
||||
%patch21 -p1
|
||||
%patch22 -p1
|
||||
%patch23 -p1
|
||||
%patch24 -p1
|
||||
|
||||
|
||||
%build
|
||||
@ -2569,6 +2573,12 @@ end
|
||||
%doc rpm.doc/changelogs/libcc1/ChangeLog*
|
||||
|
||||
%changelog
|
||||
* Tue Sep 14 2021 eastb233 <xiezhiheng@huawei.com> - 10.3.1-20210914.5
|
||||
- Type:Sync
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:Sync patch from openeuler/gcc
|
||||
|
||||
* Fri Aug 27 2021 eastb233 <xiezhiheng@huawei.com> - 10.3.1-20210827.4
|
||||
- Type:RISC-V
|
||||
- ID:NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user