Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-25 Thread Sudakshina Das

Hi Martin

On 25/05/18 10:45, Martin Liška wrote:

On 05/21/2018 04:42 PM, Sudakshina Das wrote:

On 21/05/18 15:00, Rainer Orth wrote:

Hi Martin,


Thanks for opened eyes, following patch will fix that.
It's quite obvious, I'll install it right after tests will finish.


unfortunately, it didn't fix either issue:

* The switchlower -> switchlower1 renames in the dg-final* lines
    (attached) are still necessary to avoid the UNRESOLVED errors.
    Although obvious, I haven't installed them since ...

* ... even so

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing basic 
block"

    remains.

[...]

You are right, it's using -O2, thus your patch is right. Please install the
patch
after testing. It's obvious fix.


But what about the remaining FAIL?



Sorry to add to this, but I have also observed the following failures on  
aarch64-none-elf, aarch64-none-linux-gnu and aarch64_be-none-elf targets 
bisected to this commit:

FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7

FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2

FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7

FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2


Hi.

I've just tested sancov tests on my aarch64 and cmp0.c looks fine. Can you 
please tell me which -march, -mtune does
your board have?



FAIL: gcc.dg/tree-ssa/pr77445-2.c scan-tree-dump-not thread3 "not considered"

FAIL: gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump-not vrp2 "Jumps 
threaded"


I can confirm these 2. It's kind of expected, I will clean it up before next 
release. Jeff is aware
of that..

Martin



From my today's build, I only see the following remaining now:

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 
"Removing basic block"


FAIL: gcc.dg/tree-ssa/pr77445-2.c scan-tree-dump-not thread3 "not 
considered"


FAIL: gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump-not vrp2 "Jumps 
threaded"



Sudi



Sudi


 Rainer









Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-25 Thread Martin Liška
On 05/21/2018 04:42 PM, Sudakshina Das wrote:
> On 21/05/18 15:00, Rainer Orth wrote:
>> Hi Martin,
>>
> Thanks for opened eyes, following patch will fix that.
> It's quite obvious, I'll install it right after tests will finish.

 unfortunately, it didn't fix either issue:

 * The switchlower -> switchlower1 renames in the dg-final* lines
    (attached) are still necessary to avoid the UNRESOLVED errors.
    Although obvious, I haven't installed them since ...

 * ... even so

 FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 
 "Removing basic block"

    remains.
>> [...]
>>> You are right, it's using -O2, thus your patch is right. Please install the
>>> patch
>>> after testing. It's obvious fix.
>>
>> But what about the remaining FAIL?
>>
> 
> Sorry to add to this, but I have also observed the following failures on  
> aarch64-none-elf, aarch64-none-linux-gnu and aarch64_be-none-elf targets 
> bisected to this commit:
> 
> FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
> "__builtin___sanitizer_cov_trace_const_cmp" 7
> 
> FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
> "__builtin___sanitizer_cov_trace_switch \\(" 2
> 
> FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
> "__builtin___sanitizer_cov_trace_const_cmp" 7
> 
> FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
> "__builtin___sanitizer_cov_trace_switch \\(" 2

Hi.

I've just tested sancov tests on my aarch64 and cmp0.c looks fine. Can you 
please tell me which -march, -mtune does
your board have?

> 
> FAIL: gcc.dg/tree-ssa/pr77445-2.c scan-tree-dump-not thread3 "not considered"
> 
> FAIL: gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump-not vrp2 "Jumps 
> threaded"

I can confirm these 2. It's kind of expected, I will clean it up before next 
release. Jeff is aware
of that..

Martin

> 
> Sudi
> 
>> Rainer
>>
> 



Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-24 Thread Martin Liška

On 05/24/2018 02:28 PM, Rainer Orth wrote:

Hi Martin,


On 05/21/2018 01:18 PM, Rainer Orth wrote:

Hi Martin,


On 05/18/2018 03:55 PM, Rainer Orth wrote:

Hi Martin,


So the patch looks fine, only very very slightly binary is produced. I'm
going to install the patch so that
I can carry on more complex patches based on this one.


it seems you didn't properly test the testsuite part: I see

+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
"Removing basic block"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
"loop depth 1, count 3"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
switchlower "Invalid sum"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
switchlower "loop depth 1, count 2"

everywhere.  The log has

gcc.dg/tree-prof/update-loopch.c: dump file does not exist

Obviously you forgot the adapt the dg-final* files for the dumpfile
name.  If I do, three of the failures go away, but

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1
"Removing basic block"

remains (on 32 and 64-bit Linux/x86_64).

Please fix.

Rainer



Thanks for opened eyes, following patch will fix that.
It's quite obvious, I'll install it right after tests will finish.


unfortunately, it didn't fix either issue:

* The switchlower -> switchlower1 renames in the dg-final* lines
   (attached) are still necessary to avoid the UNRESOLVED errors.
   Although obvious, I haven't installed them since ...

* ... even so

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing basic 
block"

   remains.

Rainer


Hi.

You are right, it's using -O2, thus your patch is right. Please install the
patch
after testing. It's obvious fix.


I've now installed the fix for the dumpfile renaming.  However, you've
still done nothing about the remaining failure.


Thanks. Is the last remaining one: gcc.dg/tree-prof/update-loopch.c?

Thanks,
Martin



Rainer





Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-24 Thread Martin Liška

On 05/21/2018 04:42 PM, Sudakshina Das wrote:

On 21/05/18 15:00, Rainer Orth wrote:

Hi Martin,


Thanks for opened eyes, following patch will fix that.
It's quite obvious, I'll install it right after tests will finish.


unfortunately, it didn't fix either issue:

* The switchlower -> switchlower1 renames in the dg-final* lines
   (attached) are still necessary to avoid the UNRESOLVED errors.
   Although obvious, I haven't installed them since ...

* ... even so

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing basic 
block"

   remains.

[...]

You are right, it's using -O2, thus your patch is right. Please install the
patch
after testing. It's obvious fix.


But what about the remaining FAIL?



Sorry to add to this, but I have also observed the following failures on  
aarch64-none-elf, aarch64-none-linux-gnu and aarch64_be-none-elf targets 
bisected to this commit:

FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7

FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2

FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7

FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2

FAIL: gcc.dg/tree-ssa/pr77445-2.c scan-tree-dump-not thread3 "not considered"

FAIL: gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump-not vrp2 "Jumps 
threaded"

Sudi


Hi.

Sorry for the breakage, I'll fix it in couple of days.

Martin




Rainer







Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-24 Thread Rainer Orth
Hi Martin,

> On 05/21/2018 01:18 PM, Rainer Orth wrote:
>> Hi Martin,
>> 
>>> On 05/18/2018 03:55 PM, Rainer Orth wrote:
 Hi Martin,

> So the patch looks fine, only very very slightly binary is produced. I'm
> going to install the patch so that
> I can carry on more complex patches based on this one.

 it seems you didn't properly test the testsuite part: I see

 +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
 "Removing basic block"
 +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
 "loop depth 1, count 3"
 +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
 switchlower "Invalid sum"
 +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
 switchlower "loop depth 1, count 2"

 everywhere.  The log has

 gcc.dg/tree-prof/update-loopch.c: dump file does not exist

 Obviously you forgot the adapt the dg-final* files for the dumpfile
 name.  If I do, three of the failures go away, but

 FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1
 "Removing basic block"

 remains (on 32 and 64-bit Linux/x86_64).

 Please fix.

Rainer

>>>
>>> Thanks for opened eyes, following patch will fix that.
>>> It's quite obvious, I'll install it right after tests will finish.
>> 
>> unfortunately, it didn't fix either issue:
>> 
>> * The switchlower -> switchlower1 renames in the dg-final* lines
>>   (attached) are still necessary to avoid the UNRESOLVED errors.
>>   Although obvious, I haven't installed them since ...
>> 
>> * ... even so
>> 
>> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
>> basic block"
>> 
>>   remains.
>> 
>>  Rainer
>
> Hi.
>
> You are right, it's using -O2, thus your patch is right. Please install the
> patch
> after testing. It's obvious fix.

I've now installed the fix for the dumpfile renaming.  However, you've
still done nothing about the remaining failure.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-21 Thread Sudakshina Das

On 21/05/18 15:00, Rainer Orth wrote:

Hi Martin,


Thanks for opened eyes, following patch will fix that.
It's quite obvious, I'll install it right after tests will finish.


unfortunately, it didn't fix either issue:

* The switchlower -> switchlower1 renames in the dg-final* lines
   (attached) are still necessary to avoid the UNRESOLVED errors.
   Although obvious, I haven't installed them since ...

* ... even so

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing basic 
block"

   remains.

[...]

You are right, it's using -O2, thus your patch is right. Please install the
patch
after testing. It's obvious fix.


But what about the remaining FAIL?



Sorry to add to this, but I have also observed the following failures on 
 aarch64-none-elf, aarch64-none-linux-gnu and aarch64_be-none-elf 
targets bisected to this commit:


FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7


FAIL: gcc.dg/sancov/cmp0.c   -O0   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2


FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_const_cmp" 7


FAIL: gcc.dg/sancov/cmp0.c   -O0 -g   scan-tree-dump-times optimized 
"__builtin___sanitizer_cov_trace_switch \\(" 2


FAIL: gcc.dg/tree-ssa/pr77445-2.c scan-tree-dump-not thread3 "not 
considered"


FAIL: gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump-not vrp2 "Jumps 
threaded"


Sudi


Rainer





Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-21 Thread Rainer Orth
Hi Martin,

>>> Thanks for opened eyes, following patch will fix that.
>>> It's quite obvious, I'll install it right after tests will finish.
>> 
>> unfortunately, it didn't fix either issue:
>> 
>> * The switchlower -> switchlower1 renames in the dg-final* lines
>>   (attached) are still necessary to avoid the UNRESOLVED errors.
>>   Although obvious, I haven't installed them since ...
>> 
>> * ... even so
>> 
>> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
>> basic block"
>> 
>>   remains.
[...]
> You are right, it's using -O2, thus your patch is right. Please install the
> patch
> after testing. It's obvious fix.

But what about the remaining FAIL?

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-21 Thread Martin Liška
On 05/21/2018 01:18 PM, Rainer Orth wrote:
> Hi Martin,
> 
>> On 05/18/2018 03:55 PM, Rainer Orth wrote:
>>> Hi Martin,
>>>
 So the patch looks fine, only very very slightly binary is produced. I'm
 going to install the patch so that
 I can carry on more complex patches based on this one.
>>>
>>> it seems you didn't properly test the testsuite part: I see
>>>
>>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
>>> "Removing basic block"
>>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
>>> "loop depth 1, count 3"
>>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
>>> switchlower "Invalid sum"
>>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
>>> switchlower "loop depth 1, count 2"
>>>
>>> everywhere.  The log has
>>>
>>> gcc.dg/tree-prof/update-loopch.c: dump file does not exist
>>>
>>> Obviously you forgot the adapt the dg-final* files for the dumpfile
>>> name.  If I do, three of the failures go away, but
>>>
>>> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1
>>> "Removing basic block"
>>>
>>> remains (on 32 and 64-bit Linux/x86_64).
>>>
>>> Please fix.
>>>
>>> Rainer
>>>
>>
>> Thanks for opened eyes, following patch will fix that.
>> It's quite obvious, I'll install it right after tests will finish.
> 
> unfortunately, it didn't fix either issue:
> 
> * The switchlower -> switchlower1 renames in the dg-final* lines
>   (attached) are still necessary to avoid the UNRESOLVED errors.
>   Although obvious, I haven't installed them since ...
> 
> * ... even so
> 
> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
> basic block"
> 
>   remains.
> 
>   Rainer

Hi.

You are right, it's using -O2, thus your patch is right. Please install the 
patch 
after testing. It's obvious fix.

Martin

> 
> 
>> From 7ae0c7d4a81166dbf5e9dff5d35e4c9d63b1c058 Mon Sep 17 00:00:00 2001
>> From: marxin 
>> Date: Fri, 18 May 2018 16:17:57 +0200
>> Subject: [PATCH] Remove redundand pass pass_lower_switch.
>>
>> gcc/ChangeLog:
>>
>> 2018-05-18  Martin Liska  
>>
>>  * passes.def: Remove a redundant pass.
>> ---
>>  gcc/passes.def | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/gcc/passes.def b/gcc/passes.def
>> index 050009464ea..055d354f959 100644
>> --- a/gcc/passes.def
>> +++ b/gcc/passes.def
>> @@ -399,9 +399,8 @@ along with GCC; see the file COPYING3.  If not see
>>NEXT_PASS (pass_lower_vaarg);
>>NEXT_PASS (pass_lower_vector);
>>NEXT_PASS (pass_lower_complex_O0);
>> -  NEXT_PASS (pass_lower_switch_O0);
>>NEXT_PASS (pass_sancov_O0);
>> -  NEXT_PASS (pass_lower_switch);
>> +  NEXT_PASS (pass_lower_switch_O0);
>>NEXT_PASS (pass_asan_O0);
>>NEXT_PASS (pass_tsan_O0);
>>NEXT_PASS (pass_sanopt);
> 




Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-21 Thread Rainer Orth
Hi Martin,

> On 05/18/2018 03:55 PM, Rainer Orth wrote:
>> Hi Martin,
>> 
>>> So the patch looks fine, only very very slightly binary is produced. I'm
>>> going to install the patch so that
>>> I can carry on more complex patches based on this one.
>> 
>> it seems you didn't properly test the testsuite part: I see
>> 
>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
>> "Removing basic block"
>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower
>> "loop depth 1, count 3"
>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
>> switchlower "Invalid sum"
>> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not
>> switchlower "loop depth 1, count 2"
>> 
>> everywhere.  The log has
>> 
>> gcc.dg/tree-prof/update-loopch.c: dump file does not exist
>> 
>> Obviously you forgot the adapt the dg-final* files for the dumpfile
>> name.  If I do, three of the failures go away, but
>> 
>> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1
>> "Removing basic block"
>> 
>> remains (on 32 and 64-bit Linux/x86_64).
>> 
>> Please fix.
>> 
>>  Rainer
>> 
>
> Thanks for opened eyes, following patch will fix that.
> It's quite obvious, I'll install it right after tests will finish.

unfortunately, it didn't fix either issue:

* The switchlower -> switchlower1 renames in the dg-final* lines
  (attached) are still necessary to avoid the UNRESOLVED errors.
  Although obvious, I haven't installed them since ...

* ... even so

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
basic block"

  remains.

Rainer


> From 7ae0c7d4a81166dbf5e9dff5d35e4c9d63b1c058 Mon Sep 17 00:00:00 2001
> From: marxin 
> Date: Fri, 18 May 2018 16:17:57 +0200
> Subject: [PATCH] Remove redundand pass pass_lower_switch.
>
> gcc/ChangeLog:
>
> 2018-05-18  Martin Liska  
>
>   * passes.def: Remove a redundant pass.
> ---
>  gcc/passes.def | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/gcc/passes.def b/gcc/passes.def
> index 050009464ea..055d354f959 100644
> --- a/gcc/passes.def
> +++ b/gcc/passes.def
> @@ -399,9 +399,8 @@ along with GCC; see the file COPYING3.  If not see
>NEXT_PASS (pass_lower_vaarg);
>NEXT_PASS (pass_lower_vector);
>NEXT_PASS (pass_lower_complex_O0);
> -  NEXT_PASS (pass_lower_switch_O0);
>NEXT_PASS (pass_sancov_O0);
> -  NEXT_PASS (pass_lower_switch);
> +  NEXT_PASS (pass_lower_switch_O0);
>NEXT_PASS (pass_asan_O0);
>NEXT_PASS (pass_tsan_O0);
>NEXT_PASS (pass_sanopt);

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


diff --git a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
--- a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
@@ -16,7 +16,7 @@ main ()
edge.  */
 /* autofdo cannot do that precise counts */
 /* { dg-final-use-not-autofdo { scan-ipa-dump "loop depth 1, count 4" "profile"} } */
-/* { dg-final-use-not-autofdo { scan-tree-dump "loop depth 1, count 3" "switchlower"} } */
-/* { dg-final-use-not-autofdo { scan-tree-dump-not "loop depth 1, count 2" "switchlower"} } */
-/* { dg-final-use-not-autofdo { scan-tree-dump "Removing basic block" "switchlower"} } */
-/* { dg-final-use { scan-tree-dump-not "Invalid sum" "switchlower"} } */
+/* { dg-final-use-not-autofdo { scan-tree-dump "loop depth 1, count 3" "switchlower1"} } */
+/* { dg-final-use-not-autofdo { scan-tree-dump-not "loop depth 1, count 2" "switchlower1"} } */
+/* { dg-final-use-not-autofdo { scan-tree-dump "Removing basic block" "switchlower1"} } */
+/* { dg-final-use { scan-tree-dump-not "Invalid sum" "switchlower1"} } */


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-18 Thread Martin Liška
On 05/18/2018 03:55 PM, Rainer Orth wrote:
> Hi Martin,
> 
>> So the patch looks fine, only very very slightly binary is produced. I'm
>> going to install the patch so that
>> I can carry on more complex patches based on this one.
> 
> it seems you didn't properly test the testsuite part: I see
> 
> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower 
> "Removing basic block"
> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower 
> "loop depth 1, count 3"
> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not switchlower 
> "Invalid sum"
> +UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not switchlower 
> "loop depth 1, count 2"
> 
> everywhere.  The log has
> 
> gcc.dg/tree-prof/update-loopch.c: dump file does not exist
> 
> Obviously you forgot the adapt the dg-final* files for the dumpfile
> name.  If I do, three of the failures go away, but
> 
> FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
> basic block"
> 
> remains (on 32 and 64-bit Linux/x86_64).
> 
> Please fix.
> 
>   Rainer
> 

Thanks for opened eyes, following patch will fix that.
It's quite obvious, I'll install it right after tests will finish.

Martin
>From 7ae0c7d4a81166dbf5e9dff5d35e4c9d63b1c058 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Fri, 18 May 2018 16:17:57 +0200
Subject: [PATCH] Remove redundand pass pass_lower_switch.

gcc/ChangeLog:

2018-05-18  Martin Liska  

	* passes.def: Remove a redundant pass.
---
 gcc/passes.def | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/passes.def b/gcc/passes.def
index 050009464ea..055d354f959 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -399,9 +399,8 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_lower_vaarg);
   NEXT_PASS (pass_lower_vector);
   NEXT_PASS (pass_lower_complex_O0);
-  NEXT_PASS (pass_lower_switch_O0);
   NEXT_PASS (pass_sancov_O0);
-  NEXT_PASS (pass_lower_switch);
+  NEXT_PASS (pass_lower_switch_O0);
   NEXT_PASS (pass_asan_O0);
   NEXT_PASS (pass_tsan_O0);
   NEXT_PASS (pass_sanopt);
-- 
2.16.3



Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-18 Thread Rainer Orth
Hi Martin,

> So the patch looks fine, only very very slightly binary is produced. I'm
> going to install the patch so that
> I can carry on more complex patches based on this one.

it seems you didn't properly test the testsuite part: I see

+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower 
"Removing basic block"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower "loop 
depth 1, count 3"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not switchlower 
"Invalid sum"
+UNRESOLVED: gcc.dg/tree-prof/update-loopch.c scan-tree-dump-not switchlower 
"loop depth 1, count 2"

everywhere.  The log has

gcc.dg/tree-prof/update-loopch.c: dump file does not exist

Obviously you forgot the adapt the dg-final* files for the dumpfile
name.  If I do, three of the failures go away, but

FAIL: gcc.dg/tree-prof/update-loopch.c scan-tree-dump switchlower1 "Removing 
basic block"

remains (on 32 and 64-bit Linux/x86_64).

Please fix.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-05-17 Thread Martin Liška
On 01/15/2018 12:22 AM, Bernhard Reutner-Fischer wrote:
> Can you please post CSiBE numbers? Ideally throwing in gcc-3.4.6 numbers too?
> 
> thanks, 

Hi.

I've just retested the patch and looks fine. There are numbers of CSiBE. I'm 
sorry I don't
have such old version of GCC:

+---++--+--+-++
|  object   | trunk  |  Trunk w/ patch  |Gcc 7.3.1 | patch vs. 
trunk | Gcc 7.3.1 vs trunk |
+---++--+--+-++
| buf.c.o   |   2531 | 2531 | 2531 |
   0 |  0 |
| ccl.c.o   |   2520 | 2520 | 2519 |
   0 | -1 |
| dfa.c.o   |   9909 | 9909 | 9909 |
   0 |  0 |
| ecs.c.o   |   1432 | 1432 | 1432 |
   0 |  0 |
| filter.c.o|   4810 | 4810 | 4810 |
   0 |  0 |
| gen.c.o   |  28696 |28696 |28805 |
   0 |109 |
| libmain.c.o   | 88 |   88 |   88 |
   0 |  0 |
| libyywrap.c.o | 54 |   54 |   67 |
   0 | 13 |
| main.c.o  |  22132 |22132 |22129 |
   0 | -3 |
| misc.c.o  |   9765 | 9765 | 9811 |
   0 | 46 |
| nfa.c.o   |   6449 | 6467 | 6449 |
  18 |  0 |
| options.c.o   |   1240 | 1240 | 1240 |
   0 |  0 |
| parse.c.o |  15737 |15737 |15742 |
   0 |  5 |
| regex.c.o |   1374 | 1374 | 1374 |
   0 |  0 |
| scan.c.o  |  66844 |66896 |66944 |
  52 |100 |
| scanflags.c.o |422 |  422 |  435 |
   0 | 13 |
| scanopt.c.o   |   8170 | 8201 | 8198 |
  31 | 28 |
| skel.c.o  |  91010 |91010 |91010 |
   0 |  0 |
| sym.c.o   |   1796 | 1796 | 1796 |
   0 |  0 |
| tables.c.o|   5000 | 5070 | 4998 |
  70 | -2 |
| tables_shared.c.o |122 |  122 |  122 |
   0 |  0 |
| tblcmp.c.o|   5587 | 5587 | 5578 |
   0 | -9 |
| yylex.c.o |   2166 | 2332 | 2122 |
 166 |-44 |
| blocksort.c.o |  13850 |13850 |13862 |
   0 | 12 |
| bzip2.c.o |  23540 |23702 |23535 |
 162 | -5 |
| bzip2recover.c.o  |   4863 | 4863 | 4865 |
   0 |  2 |
| bzlib.c.o |  21359 |21433 |21393 |
  74 | 34 |
| compress.c.o  |  24424 |24424 |24409 |
   0 |-15 |
| crctable.c.o  |  0 |0 |0 |
   0 |  0 |
| decompress.c.o|  23467 |23467 |23464 |
   0 | -3 |
| dlltest.c.o   |   1213 | 1213 | 1213 |
   0 |  0 |
| huffman.c.o   |   2180 | 2180 | 2180 |
   0 |  0 |
| mk251.c.o |103 |  103 |  103 |
   0 |  0 |
| randtable.c.o |  0 |0 |0 |
   0 |  0 |
| spewG.c.o |477 |  477 |  480 |
   0 |  3 |
| unzcrash.c.o  |   1284 | 1284 | 1284 |
   0 |  0 |
| SUM   | 404614 |   405187 |   404897 |
 573 |283 |
| ratio || 1.00141616454201 | 0.99928428108503 |
 ||
+---++--+--+-++

So the patch looks fine, only very very slightly binary is produced. I'm going 
to install the patch so that
I can carry on more complex patches

Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-01-14 Thread Bernhard Reutner-Fischer
On 10 January 2018 15:59:28 CET, "Martin Liška"  wrote:
>On 01/10/2018 02:13 PM, Richard Biener wrote:
>> On Tue, Jan 9, 2018 at 7:29 PM, Jeff Law  wrote:
>>> On 01/09/2018 07:43 AM, Martin Liška wrote:
 On 09/20/2017 05:00 PM, Jeff Law wrote:
> On 09/20/2017 01:24 AM, Martin Liška wrote:
>
>>
>> Hello.
>>
>> Thank you Jeff for very verbose explanation what's happening. I'm
>planning to do
>> follow-up of this patch that will include clustering for
>bit-tests and jump tables.
>> Maybe that will make aforementioned issues even more difficult,
>but we'll see.
> FWIW, the DOM changes to simplify the conditionals seem to help
>both
> cases, trigger reasonably consistently in a bootstrap and for some
> subset of the triggers actually result in transformations that
>allow
> other passes to do a better job in the common (-O2) case.  So my
> inclination is to polish them a bit further get them on the trunk.
>
> My recommendation is to ignore the two regressions for now and
>focus on
> the cleanups you're trying to do.
>
> jeff
>

 Hello.

 Some time ago I've decided that I'll make patch submission of
>switch clustering
 in next stage1. However, this patch can be applied as is in this
>stage3. Would
 it be possible or is it too late?
>>> I'll let Richi make the call here.  FWIW, the DOM changes to avoid
>the
>>> two missed-optimization regressions you ran into are on the trunk,
>so
>>> that's no longer a blocking issue.
>> 
>> If you are fine with waiting then please wait ;)
>
>Yep, it's not urgent.

Can you please post CSiBE numbers? Ideally throwing in gcc-3.4.6 numbers too?

thanks, 


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-01-10 Thread Martin Liška
On 01/10/2018 02:13 PM, Richard Biener wrote:
> On Tue, Jan 9, 2018 at 7:29 PM, Jeff Law  wrote:
>> On 01/09/2018 07:43 AM, Martin Liška wrote:
>>> On 09/20/2017 05:00 PM, Jeff Law wrote:
 On 09/20/2017 01:24 AM, Martin Liška wrote:

>
> Hello.
>
> Thank you Jeff for very verbose explanation what's happening. I'm 
> planning to do
> follow-up of this patch that will include clustering for bit-tests and 
> jump tables.
> Maybe that will make aforementioned issues even more difficult, but we'll 
> see.
 FWIW, the DOM changes to simplify the conditionals seem to help both
 cases, trigger reasonably consistently in a bootstrap and for some
 subset of the triggers actually result in transformations that allow
 other passes to do a better job in the common (-O2) case.  So my
 inclination is to polish them a bit further get them on the trunk.

 My recommendation is to ignore the two regressions for now and focus on
 the cleanups you're trying to do.

 jeff

>>>
>>> Hello.
>>>
>>> Some time ago I've decided that I'll make patch submission of switch 
>>> clustering
>>> in next stage1. However, this patch can be applied as is in this stage3. 
>>> Would
>>> it be possible or is it too late?
>> I'll let Richi make the call here.  FWIW, the DOM changes to avoid the
>> two missed-optimization regressions you ran into are on the trunk, so
>> that's no longer a blocking issue.
> 
> If you are fine with waiting then please wait ;)

Yep, it's not urgent.

Thanks.
Martin

> 
> Richard.
> 
>> jeff



Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-01-10 Thread Richard Biener
On Tue, Jan 9, 2018 at 7:29 PM, Jeff Law  wrote:
> On 01/09/2018 07:43 AM, Martin Liška wrote:
>> On 09/20/2017 05:00 PM, Jeff Law wrote:
>>> On 09/20/2017 01:24 AM, Martin Liška wrote:
>>>

 Hello.

 Thank you Jeff for very verbose explanation what's happening. I'm planning 
 to do
 follow-up of this patch that will include clustering for bit-tests and 
 jump tables.
 Maybe that will make aforementioned issues even more difficult, but we'll 
 see.
>>> FWIW, the DOM changes to simplify the conditionals seem to help both
>>> cases, trigger reasonably consistently in a bootstrap and for some
>>> subset of the triggers actually result in transformations that allow
>>> other passes to do a better job in the common (-O2) case.  So my
>>> inclination is to polish them a bit further get them on the trunk.
>>>
>>> My recommendation is to ignore the two regressions for now and focus on
>>> the cleanups you're trying to do.
>>>
>>> jeff
>>>
>>
>> Hello.
>>
>> Some time ago I've decided that I'll make patch submission of switch 
>> clustering
>> in next stage1. However, this patch can be applied as is in this stage3. 
>> Would
>> it be possible or is it too late?
> I'll let Richi make the call here.  FWIW, the DOM changes to avoid the
> two missed-optimization regressions you ran into are on the trunk, so
> that's no longer a blocking issue.

If you are fine with waiting then please wait ;)

Richard.

> jeff


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-01-09 Thread Jeff Law
On 01/09/2018 07:43 AM, Martin Liška wrote:
> On 09/20/2017 05:00 PM, Jeff Law wrote:
>> On 09/20/2017 01:24 AM, Martin Liška wrote:
>>
>>>
>>> Hello.
>>>
>>> Thank you Jeff for very verbose explanation what's happening. I'm planning 
>>> to do
>>> follow-up of this patch that will include clustering for bit-tests and jump 
>>> tables.
>>> Maybe that will make aforementioned issues even more difficult, but we'll 
>>> see.
>> FWIW, the DOM changes to simplify the conditionals seem to help both
>> cases, trigger reasonably consistently in a bootstrap and for some
>> subset of the triggers actually result in transformations that allow
>> other passes to do a better job in the common (-O2) case.  So my
>> inclination is to polish them a bit further get them on the trunk.
>>
>> My recommendation is to ignore the two regressions for now and focus on
>> the cleanups you're trying to do.
>>
>> jeff
>>
> 
> Hello.
> 
> Some time ago I've decided that I'll make patch submission of switch 
> clustering
> in next stage1. However, this patch can be applied as is in this stage3. Would
> it be possible or is it too late?
I'll let Richi make the call here.  FWIW, the DOM changes to avoid the
two missed-optimization regressions you ran into are on the trunk, so
that's no longer a blocking issue.

jeff


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2018-01-09 Thread Martin Liška
On 09/20/2017 05:00 PM, Jeff Law wrote:
> On 09/20/2017 01:24 AM, Martin Liška wrote:
> 
>>
>> Hello.
>>
>> Thank you Jeff for very verbose explanation what's happening. I'm planning 
>> to do
>> follow-up of this patch that will include clustering for bit-tests and jump 
>> tables.
>> Maybe that will make aforementioned issues even more difficult, but we'll 
>> see.
> FWIW, the DOM changes to simplify the conditionals seem to help both
> cases, trigger reasonably consistently in a bootstrap and for some
> subset of the triggers actually result in transformations that allow
> other passes to do a better job in the common (-O2) case.  So my
> inclination is to polish them a bit further get them on the trunk.
> 
> My recommendation is to ignore the two regressions for now and focus on
> the cleanups you're trying to do.
> 
> jeff
> 

Hello.

Some time ago I've decided that I'll make patch submission of switch clustering
in next stage1. However, this patch can be applied as is in this stage3. Would
it be possible or is it too late?

Thanks,
Martin


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2017-09-21 Thread Bernhard Reutner-Fischer
On 20 September 2017 17:00:13 CEST, Jeff Law  wrote:
>On 09/20/2017 01:24 AM, Martin Liška wrote:
>
>> 
>> Hello.
>> 
>> Thank you Jeff for very verbose explanation what's happening. I'm
>planning to do
>> follow-up of this patch that will include clustering for bit-tests
>and jump tables.
>> Maybe that will make aforementioned issues even more difficult, but
>we'll see.
>FWIW, the DOM changes to simplify the conditionals seem to help both
>cases, trigger reasonably consistently in a bootstrap and for some
>subset of the triggers actually result in transformations that allow
>other passes to do a better job in the common (-O2) case.  So my
>inclination is to polish them a bit further get them on the trunk.
>
>My recommendation is to ignore the two regressions for now and focus on
>the cleanups you're trying to do.

Can you please post CSiBE numbers?
Ideally throwing in gcc-3.4.6 numbers too?

Just curious since I stumbled across suboptimal handling of switch statements 
some time ago:
gcc.gnu.org/ml/gcc-patches/2007-06/msg01648.html

thanks,


Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2017-09-20 Thread Jeff Law
On 09/20/2017 01:24 AM, Martin Liška wrote:

> 
> Hello.
> 
> Thank you Jeff for very verbose explanation what's happening. I'm planning to 
> do
> follow-up of this patch that will include clustering for bit-tests and jump 
> tables.
> Maybe that will make aforementioned issues even more difficult, but we'll see.
FWIW, the DOM changes to simplify the conditionals seem to help both
cases, trigger reasonably consistently in a bootstrap and for some
subset of the triggers actually result in transformations that allow
other passes to do a better job in the common (-O2) case.  So my
inclination is to polish them a bit further get them on the trunk.

My recommendation is to ignore the two regressions for now and focus on
the cleanups you're trying to do.

jeff



Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2017-09-20 Thread Martin Liška
On 09/16/2017 12:19 AM, Jeff Law wrote:
> On 09/14/2017 06:17 AM, Martin Liška wrote:
>> Hello.
>>
>> As mentioned at Cauldron 2017, second step in switch lowering should be 
>> massive
>> simplification in code that does expansion of balanced tree. Basically it 
>> includes
>> VRP and DCE, which we can for obvious reason do by our own.
>>
>> The patch does that, and introduces a separate pass for -O0 that's 
>> responsible
>> for lowering at the end of tree pass.
>>
>> There's a small fallback that I would like to discuss:
>>
>> 1) vrp105.c - there's no longer catches threading opportunity in between 
>> default cases:
>> adding Patrick who can probably help why is the opportunity skipped with 
>> expanded tree
> Well, VRP knows how to analyze a switch statement and determine when
> paths out of one switch imply a particular case will be taken in a later
> switch.  In this particular case we're trying to verify that the default
> case in the first switch threads directly to the default case in the
> second (though it seems we ought to be able to totally thread the cases).
> 
> Obviously we don't have switches anymore after your lowering pass.  But
> ISTM we still ought to be able to evaluate how your lowering affects
> jump threading on this case.  In theory the lowered switch statements
> should be easier to thread.
> 
> Reality is sadly different.  There's two cases to consider.  One when i
> < 0 (should go to first default, then directly to second default).  The
> other when i > 1 which should also go to the first default, then
> directly to the second default).
> 
> When i < 0 we do in fact thread through the second switch and go from
> the first default case directly to the second default case.
> 
> When i > 1 we still go through the test for the second switch.
> 
> These are the key blocks:
> 
> ;;   basic block 2, loop depth 0, freq 1, maybe hot
> ;;prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)
> ;;pred:   ENTRY [always]  (FALLTHRU,EXECUTABLE)
>   i.0_1 = i;
>   if (i.0_1 > 0)
> goto ; [50.01%] [count: INV]
>   else
> goto ; [49.99%] [count: INV]
> ;;succ:   3 [50.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
> ;;4 [50.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)
> 
> ;;   basic block 3, loop depth 0, freq 1, maybe hot
> ;;   Invalid sum of incoming frequencies 4999, should be 1
> ;;prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)
> ;;pred:   2 [50.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
>   if (i.0_1 == 0)
> goto ; [40.00%] [count: INV]
>   else
> goto ; [60.00%] [count: INV]
> ;;succ:   14 [60.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
> ;;5 [40.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)
> 
> ;;   basic block 4, loop depth 0, freq 1, maybe hot
> ;;   Invalid sum of incoming frequencies 5001, should be 1
> ;;prev block 3, next block 5, flags: (NEW, REACHABLE, VISITED)
> ;;pred:   2 [50.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)
>   _13 = i.0_1 != 1;
>   if (_13 != 0)
> goto ; [16.68%] [count: INV]
>   else
> goto ; [83.32%] [count: INV]
> ;;succ:   6 [83.3% (guessed)]  (FALSE_VALUE,EXECUTABLE)
> ;;13 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)
> 
> [ ... ]
> 
> ;;   basic block 9, loop depth 0, freq , maybe hot
> ;;   Invalid sum of incoming frequencies 3999, should be 
> ;;prev block 8, next block 10, flags: (NEW, REACHABLE, VISITED)
> ;;pred:   13 [always]  (FALLTHRU,EXECUTABLE)
> ;;7 [always (guessed)]  (TRUE_VALUE,EXECUTABLE)
>   # prephitmp_19 = PHI 
>   _2 = prephitmp_19 != 1;
>   if (_2 != 0)
> goto ; [16.68%] [count: INV]
>   else
> goto ; [83.32%] [count: INV]
> ;;succ:   11 [83.3% (guessed)]  (FALSE_VALUE,EXECUTABLE)
> ;;12 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)
> 
> [ ... ]
> ;;   basic block 13, loop depth 0, freq 1668, maybe hot
> ;;prev block 12, next block 14, flags: (NEW, REACHABLE, VISITED)
> ;;pred:   4 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)
>   # prephitmp_15 = PHI 
>   goto ; [100.00%] [count: INV]
> ;;succ:   9 [always]  (FALLTHRU,EXECUTABLE)
> 
> 
> 
> WHen bb9 is reached by bb13 we know by back substitution that the assignemnt
> 
>  _2 = prehitmp_19 != 1
>  _2 = prehitmp_15 != 1
>  _2 = i.0_1 != 1
> 
> And we should know enough about the range of i.0_1 to determine that is
> true which would allow us to thread the jump.  But a few things get in
> the way.
> 
> First, the VRP thread doesn't try hard at all to simplify gimple
> assignments.  It really just tries to simplify gimple_cond and
> gimple_switch.  This could be trivially improved.
> 
> So if I do the right things by hand we end up trying to evaluate i.0_1
> != 1.  So that's good.  But we don't get a useful result back from
> vrp_evaluate_conditional.  WHy?  Because the recorded range for i.0_1 is
> [1,INF] -- that's the global range for i.0_1 not the range on the path.
>

Re: [PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2017-09-15 Thread Jeff Law
On 09/14/2017 06:17 AM, Martin Liška wrote:
> Hello.
> 
> As mentioned at Cauldron 2017, second step in switch lowering should be 
> massive
> simplification in code that does expansion of balanced tree. Basically it 
> includes
> VRP and DCE, which we can for obvious reason do by our own.
> 
> The patch does that, and introduces a separate pass for -O0 that's responsible
> for lowering at the end of tree pass.
> 
> There's a small fallback that I would like to discuss:
> 
> 1) vrp105.c - there's no longer catches threading opportunity in between 
> default cases:
> adding Patrick who can probably help why is the opportunity skipped with 
> expanded tree
Well, VRP knows how to analyze a switch statement and determine when
paths out of one switch imply a particular case will be taken in a later
switch.  In this particular case we're trying to verify that the default
case in the first switch threads directly to the default case in the
second (though it seems we ought to be able to totally thread the cases).

Obviously we don't have switches anymore after your lowering pass.  But
ISTM we still ought to be able to evaluate how your lowering affects
jump threading on this case.  In theory the lowered switch statements
should be easier to thread.

Reality is sadly different.  There's two cases to consider.  One when i
< 0 (should go to first default, then directly to second default).  The
other when i > 1 which should also go to the first default, then
directly to the second default).

When i < 0 we do in fact thread through the second switch and go from
the first default case directly to the second default case.

When i > 1 we still go through the test for the second switch.

These are the key blocks:

;;   basic block 2, loop depth 0, freq 1, maybe hot
;;prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)
;;pred:   ENTRY [always]  (FALLTHRU,EXECUTABLE)
  i.0_1 = i;
  if (i.0_1 > 0)
goto ; [50.01%] [count: INV]
  else
goto ; [49.99%] [count: INV]
;;succ:   3 [50.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
;;4 [50.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)

;;   basic block 3, loop depth 0, freq 1, maybe hot
;;   Invalid sum of incoming frequencies 4999, should be 1
;;prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)
;;pred:   2 [50.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
  if (i.0_1 == 0)
goto ; [40.00%] [count: INV]
  else
goto ; [60.00%] [count: INV]
;;succ:   14 [60.0% (guessed)]  (FALSE_VALUE,EXECUTABLE)
;;5 [40.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)

;;   basic block 4, loop depth 0, freq 1, maybe hot
;;   Invalid sum of incoming frequencies 5001, should be 1
;;prev block 3, next block 5, flags: (NEW, REACHABLE, VISITED)
;;pred:   2 [50.0% (guessed)]  (TRUE_VALUE,EXECUTABLE)
  _13 = i.0_1 != 1;
  if (_13 != 0)
goto ; [16.68%] [count: INV]
  else
goto ; [83.32%] [count: INV]
;;succ:   6 [83.3% (guessed)]  (FALSE_VALUE,EXECUTABLE)
;;13 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)

[ ... ]

;;   basic block 9, loop depth 0, freq , maybe hot
;;   Invalid sum of incoming frequencies 3999, should be 
;;prev block 8, next block 10, flags: (NEW, REACHABLE, VISITED)
;;pred:   13 [always]  (FALLTHRU,EXECUTABLE)
;;7 [always (guessed)]  (TRUE_VALUE,EXECUTABLE)
  # prephitmp_19 = PHI 
  _2 = prephitmp_19 != 1;
  if (_2 != 0)
goto ; [16.68%] [count: INV]
  else
goto ; [83.32%] [count: INV]
;;succ:   11 [83.3% (guessed)]  (FALSE_VALUE,EXECUTABLE)
;;12 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)

[ ... ]
;;   basic block 13, loop depth 0, freq 1668, maybe hot
;;prev block 12, next block 14, flags: (NEW, REACHABLE, VISITED)
;;pred:   4 [16.7% (guessed)]  (TRUE_VALUE,EXECUTABLE)
  # prephitmp_15 = PHI 
  goto ; [100.00%] [count: INV]
;;succ:   9 [always]  (FALLTHRU,EXECUTABLE)



WHen bb9 is reached by bb13 we know by back substitution that the assignemnt

 _2 = prehitmp_19 != 1
 _2 = prehitmp_15 != 1
 _2 = i.0_1 != 1

And we should know enough about the range of i.0_1 to determine that is
true which would allow us to thread the jump.  But a few things get in
the way.

First, the VRP thread doesn't try hard at all to simplify gimple
assignments.  It really just tries to simplify gimple_cond and
gimple_switch.  This could be trivially improved.

So if I do the right things by hand we end up trying to evaluate i.0_1
!= 1.  So that's good.  But we don't get a useful result back from
vrp_evaluate_conditional.  WHy?  Because the recorded range for i.0_1 is
[1,INF] -- that's the global range for i.0_1 not the range on the path.

Now it turns out this is precisely the problem that I've got code to
address in my queue which fixes a regression I was working on earlier
this year in the gcc-7 cycle.  It's backed up behind some improvements
to tree-ssa-uninit.c that Richi and I still need to

[PATCH][RFC] Radically simplify emission of balanced tree for switch statements.

2017-09-14 Thread Martin Liška
Hello.

As mentioned at Cauldron 2017, second step in switch lowering should be massive
simplification in code that does expansion of balanced tree. Basically it 
includes
VRP and DCE, which we can for obvious reason do by our own.

The patch does that, and introduces a separate pass for -O0 that's responsible
for lowering at the end of tree pass.

There's a small fallback that I would like to discuss:

1) vrp105.c - there's no longer catches threading opportunity in between 
default cases:
adding Patrick who can probably help why is the opportunity skipped with 
expanded tree

2) uninit-18.c where we currently report:

/home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/uninit-18.c:13:12: warning: 
‘tmp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 tmp[5] = 7;/* { dg-bogus "may be used uninitialized" } */

Am I right that the pass uses VRP?

Last question is whether the pass is properly moved in optimization pipeline?
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Thanks,
Martin

gcc/ChangeLog:

2017-09-14  Martin Liska  

* passes.def: Add pass_lower_switch and pass_lower_switch_O0.
* tree-pass.h (make_pass_lower_switch_O0): New function.
* tree-switch-conversion.c (node_has_low_bound): Remove.
(node_has_high_bound): Likewise.
(node_is_bounded): Likewise.
(class pass_lower_switch): Make it a template type and create
two instances.
(pass_lower_switch::execute): Add template argument.
(make_pass_lower_switch): New function.
(make_pass_lower_switch_O0): New function.
(do_jump_if_equal): Remove.
(emit_case_nodes): Simplify to just handle all 3 cases and leave
all the hard work to tree optimization passes.

gcc/testsuite/ChangeLog:

2017-09-14  Martin Liska  

* gcc.dg/tree-ssa/vrp104.c: Adjust dump file that is scanned.
* gcc.dg/tree-prof/update-loopch.c: Likewise.
---
 gcc/passes.def |   4 +-
 gcc/testsuite/gcc.dg/tree-prof/update-loopch.c |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/vrp104.c |   2 +-
 gcc/tree-pass.h|   1 +
 gcc/tree-switch-conversion.c   | 604 +++--
 5 files changed, 72 insertions(+), 541 deletions(-)


diff --git a/gcc/passes.def b/gcc/passes.def
index 00e75d2b55a..bb371d9bde5 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -314,6 +314,7 @@ along with GCC; see the file COPYING3.  If not see
   POP_INSERT_PASSES ()
   NEXT_PASS (pass_simduid_cleanup);
   NEXT_PASS (pass_lower_vector_ssa);
+  NEXT_PASS (pass_lower_switch);
   NEXT_PASS (pass_cse_reciprocals);
   NEXT_PASS (pass_sprintf_length, true);
   NEXT_PASS (pass_reassoc, false /* insert_powi_p */);
@@ -358,6 +359,7 @@ along with GCC; see the file COPYING3.  If not see
   /* Lower remaining pieces of GIMPLE.  */
   NEXT_PASS (pass_lower_complex);
   NEXT_PASS (pass_lower_vector_ssa);
+  NEXT_PASS (pass_lower_switch);
   /* Perform simple scalar cleanup which is constant/copy propagation.  */
   NEXT_PASS (pass_ccp, true /* nonzero_p */);
   NEXT_PASS (pass_post_ipa_warn);
@@ -393,7 +395,7 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_lower_vaarg);
   NEXT_PASS (pass_lower_vector);
   NEXT_PASS (pass_lower_complex_O0);
-  NEXT_PASS (pass_lower_switch);
+  NEXT_PASS (pass_lower_switch_O0);
   NEXT_PASS (pass_sancov_O0);
   NEXT_PASS (pass_asan_O0);
   NEXT_PASS (pass_tsan_O0);
diff --git a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
index 73efc878ec0..15baada1081 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
@@ -1,4 +1,4 @@
-/* { dg-options "-O2 -fdump-ipa-profile-blocks-details -fdump-tree-switchlower-blocks-details" } */
+/* { dg-options "-O2 -fdump-ipa-profile-blocks-details -fdump-tree-switchlower1-blocks-details" } */
 int max = 3;
 int a[8];
 int
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp104.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp104.c
index 0a952267b29..71fa3bfa2ca 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp104.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp104.c
@@ -2,7 +2,7 @@
 /* { dg-options "-O2 -fdump-tree-switchlower" }  */
 /* We scan for 2 switches as the dump file reports a transformation,
IL really contains just a single.  */
-/* { dg-final { scan-tree-dump-times "switch" 2 "switchlower" } }  */
+/* { dg-final { scan-tree-dump-times "switch" 2 "switchlower1" } }  */
 
 void foo (void);
 void bar (void);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 9f76d822abc..6ae65765431 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -410,6 +410,7 @@ extern gimple_opt_pass *make_pass_strip_predict_hints (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_lower_complex_O0 (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_lo