diff mbox

[PR66768] Skip address type iv_use if base object can't be determined

Message ID VI1PR0802MB21769664EDAAFBDDDE5C87BFE7290@VI1PR0802MB2176.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Bin Cheng March 1, 2017, 12:03 p.m. UTC
Hi,
As reported in PR66768, IVOPTs drops address-space information.  Root cause is IVOPTs fails to preserve base-object during identifying/rewriting address type iv_use for pointers converted from constant values.  This patch just skips address type iv_use if base-object can't be determined.  In the future, better handling of base-object is needed to fix the issue.  Benchmark data show the added condition is only triggered twice in spec2k6, and the two cases are actually null-pointer references.  I believe that code is dead in benchmark and is never executed.

Bootstrap and test on x86_64.  Is it OK?
2017-02-27  Bin Cheng  <bin.cheng@arm.com>

	PR tree-optimization/66768
	* tree-ssa-loop-ivopts.c (find_interesting_uses_address): Skip addr
	iv_use if base object can't be determined.

2017-02-27  Bin Cheng  <bin.cheng@arm.com>

	PR tree-optimization/66768
	* gcc.target/i386/pr66768.c: New test.

Comments

Richard Biener March 1, 2017, 12:14 p.m. UTC | #1
On Wed, Mar 1, 2017 at 1:03 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> As reported in PR66768, IVOPTs drops address-space information.  Root cause is IVOPTs fails to preserve base-object during identifying/rewriting address type iv_use for pointers converted from constant values.  This patch just skips address type iv_use if base-object can't be determined.  In the future, better handling of base-object is needed to fix the issue.  Benchmark data show the added condition is only triggered twice in spec2k6, and the two cases are actually null-pointer references.  I believe that code is dead in benchmark and is never executed.
>
> Bootstrap and test on x86_64.  Is it OK?

Ok.

Richard.

> 2017-02-27  Bin Cheng  <bin.cheng@arm.com>
>
>         PR tree-optimization/66768
>         * tree-ssa-loop-ivopts.c (find_interesting_uses_address): Skip addr
>         iv_use if base object can't be determined.
>
> 2017-02-27  Bin Cheng  <bin.cheng@arm.com>
>
>         PR tree-optimization/66768
>         * gcc.target/i386/pr66768.c: New test.
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.target/i386/pr66768.c b/gcc/testsuite/gcc.target/i386/pr66768.c
new file mode 100644
index 0000000..9a8ad1f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr66768.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef __seg_gs struct foo_s {
+  int a[20];
+} foo_t;
+
+int sum(void)
+{
+  const foo_t *p = (const foo_t *)0x1234;
+  int i, total=0;
+  for (i=0; i<20; i++)
+    total += p->a[i];
+  return total;
+}
+
+/* { dg-final { scan-assembler "add*.\[ \t\]%gs:" } } */
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index c9d16b2..f3ad373 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -2324,6 +2324,10 @@  find_interesting_uses_address (struct ivopts_data *data, gimple *stmt,
     }
 
   civ = alloc_iv (data, base, step);
+  /* Fail if base object of this memory reference is unknown.  */
+  if (civ->base_object == NULL_TREE)
+    goto fail;
+
   record_group_use (data, op_p, civ, stmt, USE_ADDRESS);
   return;