diff mbox

[PR81464] Handle equal-argument loop exit phi in expand_omp_for_static_chunk

Message ID cd85d110-4a8c-a624-6d1f-eb8f64db3fd3@mentor.com
State New
Headers show

Commit Message

Tom de Vries July 18, 2017, 4:48 p.m. UTC
Hi,

this patch fixes PR81464, an ICE in ompexpssa.

The ICE occurs in expand_omp_for_static_chunk when we're trying to fix 
up a loop exit phi:
...
   # .MEM_88 = PHI <.MEM_86(46), .MEM_86(71)>
...

It's a loop exit phi with equal arguments, which means that the variable 
has the same value when the loop is executed, and when the loop is 
skipped, in other words, it's not modified in the loop.

The fixup code ICEs when it cannot find a loop header phi corresponding 
to the loop exit phi. But it's expected that there's no loop header phi, 
given that the variable is not modified in the loop.

The patch fixes the ICE by not trying to fix up this particular kind of 
loop exit phi.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

Comments

Jakub Jelinek July 18, 2017, 4:59 p.m. UTC | #1
On Tue, Jul 18, 2017 at 06:48:56PM +0200, Tom de Vries wrote:
> Hi,
> 
> this patch fixes PR81464, an ICE in ompexpssa.
> 
> The ICE occurs in expand_omp_for_static_chunk when we're trying to fix up a
> loop exit phi:
> ...
>   # .MEM_88 = PHI <.MEM_86(46), .MEM_86(71)>
> ...

That is something that should be cleaned up by some phi opt, but if it has
been introduced during the parloops pass or too early before that, we
probably should deal with it.

> --- a/gcc/omp-expand.c
> +++ b/gcc/omp-expand.c
> @@ -4206,6 +4206,10 @@ expand_omp_for_static_chunk (struct omp_region *region,
>  	  source_location locus;
>  
>  	  phi = psi.phi ();
> +	  if (operand_equal_p (gimple_phi_arg_def (phi, 0),
> +			       redirect_edge_var_map_def (vm), 0))
> +	      continue;

Wrong formatting, please remove 2 spaces before continue;

Otherwise LGTM.

	Jakub
Tom de Vries July 18, 2017, 7:21 p.m. UTC | #2
On 07/18/2017 06:59 PM, Jakub Jelinek wrote:
> On Tue, Jul 18, 2017 at 06:48:56PM +0200, Tom de Vries wrote:
>> Hi,
>>
>> this patch fixes PR81464, an ICE in ompexpssa.
>>
>> The ICE occurs in expand_omp_for_static_chunk when we're trying to fix up a
>> loop exit phi:
>> ...
>>    # .MEM_88 = PHI <.MEM_86(46), .MEM_86(71)>
>> ...
> 
> That is something that should be cleaned up by some phi opt, but if it has
> been introduced during the parloops pass or too early before that, we
> probably should deal with it.
>

I checked, it's introduced during the parloops pass.

>> --- a/gcc/omp-expand.c
>> +++ b/gcc/omp-expand.c
>> @@ -4206,6 +4206,10 @@ expand_omp_for_static_chunk (struct omp_region *region,
>>   	  source_location locus;
>>   
>>   	  phi = psi.phi ();
>> +	  if (operand_equal_p (gimple_phi_arg_def (phi, 0),
>> +			       redirect_edge_var_map_def (vm), 0))
>> +	      continue;
> 
> Wrong formatting, please remove 2 spaces before continue;
> 
> Otherwise LGTM.
> 

Updated and committed.

Thanks,
- Tom
diff mbox

Patch

Handle equal-argument loop exit phi in expand_omp_for_static_chunk

2017-07-18  Tom de Vries  <tom@codesourcery.com>

	PR middle-end/81464
	* omp-expand.c (expand_omp_for_static_chunk): Handle equal-argument loop
	exit phi.

	* gfortran.dg/pr81464.f90: New test.

---
 gcc/omp-expand.c                      |  4 ++++
 gcc/testsuite/gfortran.dg/pr81464.f90 | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 929c530..63b91d7 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -4206,6 +4206,10 @@  expand_omp_for_static_chunk (struct omp_region *region,
 	  source_location locus;
 
 	  phi = psi.phi ();
+	  if (operand_equal_p (gimple_phi_arg_def (phi, 0),
+			       redirect_edge_var_map_def (vm), 0))
+	      continue;
+
 	  t = gimple_phi_result (phi);
 	  gcc_assert (t == redirect_edge_var_map_result (vm));
 
diff --git a/gcc/testsuite/gfortran.dg/pr81464.f90 b/gcc/testsuite/gfortran.dg/pr81464.f90
new file mode 100644
index 0000000..425cae9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr81464.f90
@@ -0,0 +1,19 @@ 
+! { dg-do compile }
+! { dg-options "--param parloops-chunk-size=2 -ftree-parallelize-loops=2 -O1" }
+
+program main
+  implicit none
+  real, dimension(:,:),allocatable :: a, b, c
+  real :: sm
+
+  allocate (a(2,2), b(2,2), c(2,2))
+
+  call random_number(a)
+  call random_number(b)
+
+  c = matmul(a,b)
+  sm = sum(c)
+
+  deallocate(a,b,c)
+
+end program main