[PR87469] ICE in record_estimate, at tree-ssa-loop-niter.c

Message ID CAELXzTMjZzcjLiFDz-3nWsbUrA--N5kjuM8Mu7fGyHi9_m+0Kg@mail.gmail.com
State New
Headers show
Series
  • [PR87469] ICE in record_estimate, at tree-ssa-loop-niter.c
Related show

Commit Message

Kugan Vivekanandarajah Oct. 27, 2018, 11:11 p.m.
Hi,

In the testcase provided in the bug report, max value for niter
estimation is off by one when it is INTEGER_CST. As a results it
asserts at the place where it is checked for equality.
Attached patch fixes this. Bootstrapped and regression tested on
x86_64-linux-gnu with no new regression. Is this OK?

Thanks,
Kugan

gcc/testsuite/ChangeLog:

2018-10-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

    PR middle-end/87469
    * g++.dg/pr87469.C: New test.

gcc/ChangeLog:

2018-10-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

    PR middle-end/87469
    * tree-ssa-loop-niter.c (number_of_iterations_popcount): Fix niter
max value.

Comments

Richard Biener Oct. 29, 2018, 2:22 p.m. | #1
On Sun, Oct 28, 2018 at 1:11 AM Kugan Vivekanandarajah
<kugan.vivekanandarajah@linaro.org> wrote:
>

> Hi,

>

> In the testcase provided in the bug report, max value for niter

> estimation is off by one when it is INTEGER_CST. As a results it

> asserts at the place where it is checked for equality.

> Attached patch fixes this. Bootstrapped and regression tested on

> x86_64-linux-gnu with no new regression. Is this OK?


OK.

> Thanks,

> Kugan

>

> gcc/testsuite/ChangeLog:

>

> 2018-10-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

>

>     PR middle-end/87469

>     * g++.dg/pr87469.C: New test.

>

> gcc/ChangeLog:

>

> 2018-10-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

>

>     PR middle-end/87469

>     * tree-ssa-loop-niter.c (number_of_iterations_popcount): Fix niter

> max value.

Patch

From 359f6aa2d603784b900feedb7ad450523695e191 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Fri, 26 Oct 2018 09:04:47 +1100
Subject: [PATCH] pr87469 V2

Change-Id: If1f7da7450ae27e24baf638861c97ff416f8484a
---
 gcc/testsuite/g++.dg/pr87469.C | 15 +++++++++++++++
 gcc/tree-ssa-loop-niter.c      |  8 +++-----
 2 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr87469.C

diff --git a/gcc/testsuite/g++.dg/pr87469.C b/gcc/testsuite/g++.dg/pr87469.C
new file mode 100644
index 0000000..2f6de97
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr87469.C
@@ -0,0 +1,15 @@ 
+/* { dg-do compile } */
+/* { dg-options "-c -w -O2"  } */
+long a;
+struct c {
+    void d(unsigned f) {
+	long e = f;
+	while (e & (e - 1))
+	  e &= e - 1;
+	a = e;
+    }
+};
+void g() {
+    c b;
+    b.d(4 + 2);
+}
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index e2bc936..e763b35 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2589,11 +2589,9 @@  number_of_iterations_popcount (loop_p loop, edge exit,
   if (TREE_CODE (call) == INTEGER_CST)
     max = tree_to_uhwi (call);
   else
-    {
-      max = TYPE_PRECISION (TREE_TYPE (src));
-      if (adjust)
-	max = max - 1;
-    }
+    max = TYPE_PRECISION (TREE_TYPE (src));
+  if (adjust)
+    max = max - 1;
 
   niter->niter = iter;
   niter->assumptions = boolean_true_node;
-- 
2.7.4