diff mbox

[Bug,tree-optimization] Fix for PR71994

Message ID 0bf1d171-3ff8-3be5-ba84-63d6d69b5c4f@linaro.org
State Superseded
Headers show

Commit Message

Kugan Vivekanandarajah July 26, 2016, 12:34 p.m. UTC
Hi Richard,

On 26/07/16 21:48, Richard Biener wrote:
> On Tue, Jul 26, 2016 at 5:13 AM, kugan

> <kugan.vivekanandarajah@linaro.org> wrote:

>> Hi,

>>

>> For testcase in pr71994, type of bb conditional result and the type of the

>> PHI stmt are different (as om.0_1 is int and the first PHI argument is

>> _bool; PHI stmt uses a constant zero that comes from edge 2). Therefore when

>> we optimize final range test stmt, we end up setting integer 1 for other PHI

>> argument. This results in ICE.

>>

>>   <bb 2>:

>>   om.0_1 = om;

>>   _2 = om.0_1 >= 0;

>>   int _3 = (int) _2;

>>   if (om.0_1 != 0)

>>     goto <bb 3>;

>>   else

>>     goto <bb 4>;

>>

>>   <bb 3>:

>>   int _4 = om.0_1 & _3;

>>   _Bool _12 = _4 != 0;

>>   <bb 4>:

>>

>>   # _Bool _13 = PHI <0(2), _12(3)>

>>

>>

>> IMHO, the fix should be that, we should check the type before replacing the

>> value (punt otherwise). Attached patch does that. Bootstrapped and

>> regression tested on x86_64-linux-gnu with no new regressions. Is this OK

>> for trunk?

>

> Ugh, this is undocumented spaghetti code I am not familiar with.  I

> can't see if it

> is safe to truncate a constant here so I'd feel safer to just punt instead.

>


Please see the attached patch,  which now constant truncation. Testing 
in progress. Is this OK for trunk if there is no new regressions?

Thanks,
Kugan

gcc/testsuite/ChangeLog:

2016-07-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

	* gcc.dg/torture/pr71994.c: New test.

gcc/ChangeLog:

2016-07-26  Kugan Vivekanandarajah  <kuganv@linaro.org>

	* tree-ssa-reassoc.c (maybe_optimize_range_tests): Check type 
compatibility.
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr71994.c b/gcc/testsuite/gcc.dg/torture/pr71994.c
index e69de29..8f5e92c 100644
--- a/gcc/testsuite/gcc.dg/torture/pr71994.c
+++ b/gcc/testsuite/gcc.dg/torture/pr71994.c
@@ -0,0 +1,14 @@ 
+/* PR tree-optimization/71994 */
+/* { dg-do compile } */
+int om, h6;
+
+void eo (void)
+{
+  const int tl = 1;
+  int ln;
+
+  h6 = (om + tl) > 0;
+  ln = om && (om & h6);
+  h6 = om;
+  om = ln < h6;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 18cf978..21742dd 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -3636,7 +3636,9 @@  maybe_optimize_range_tests (gimple *stmt)
 		  gcc_assert (bb == last_bb);
 		  new_op = ops[bbinfo[idx].first_idx++]->op;
 		}
-	      if (bbinfo[idx].op != new_op)
+	      if (bbinfo[idx].op != new_op
+		  && types_compatible_p (TREE_TYPE (new_op),
+					 TREE_TYPE (bbinfo[idx].op)))
 		{
 		  imm_use_iterator iter;
 		  use_operand_p use_p;