* [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
@ 2022-06-21 3:05 xionghuluo(罗雄虎)
2022-06-21 3:44 ` Xionghu Luo
2022-06-21 7:33 ` Richard Biener
0 siblings, 2 replies; 10+ messages in thread
From: xionghuluo(罗雄虎) @ 2022-06-21 3:05 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 3076 bytes --]
Current GCC generates:
test2:
.LFB0:
.cfi_startproc
xorl %edx, %edx
cmpl $3, (%rdi)
jle .L1
movl 16(%rdi), %eax
cmpl $1, %eax
je .L4
subl $2, %eax
cmpl $4, %eax
ja .L1
movl CSWTCH.1(,%rax,4), %edx
.L1:
movl %edx, %eax
ret
.p2align 4,,10
.p2align 3
.L4:
movl $12, %edx
jmp .L1
.cfi_endproc
.LFE0:
.size test2, .-test2
.section .rodata
.align 16
.type CSWTCH.1, @object
.size CSWTCH.1, 20
CSWTCH.1:
.long 27
.long 38
.long 18
.long 58
.long 68
With the patch attatched:
test2:
.LFB0:
.cfi_startproc
xorl %edx, %edx
cmpl $3, (%rdi)
jle .L1
movl 16(%rdi), %eax
subl $1, %eax
cmpl $5, %eax
jbe .L6
.L1:
movl %edx, %eax
ret
.p2align 4,,10
.p2align 3
.L6:
movl CSWTCH.1(,%rax,4), %edx
movl %edx, %eax
ret
.cfi_endproc
.LFE0:
.size test2, .-test2
.section .rodata
.align 16
.type CSWTCH.1, @object
.size CSWTCH.1, 24
CSWTCH.1:
.long 12
.long 27
.long 38
.long 18
.long 58
.long 68
Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
[-- Attachment #2: 0001-if-to-switch-Don-t-skip-the-first-condition-bb-when-.patch --]
[-- Type: application/octet-stream, Size: 2167 bytes --]
From 53b8cde013e976d18d6378726e7699b81b03c580 Mon Sep 17 00:00:00 2001
From: Xionghu Luo <xionghuluo@tencent.com>
Date: Thu, 9 Jun 2022 15:46:30 +0800
Subject: [PATCH] if-to-switch: Don't skip the first condition bb when
find_conditions in if-to-switch [PR105740]
The if condition is at last of first bb, so side effect statement in first BB
doesn't matter, then the first if condition could also be folded to switch
table.
gcc/ChangeLog:
* gimple-if-to-switch.cc (find_conditions): Don't skip the first
condition bb.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/if-to-switch-11.c: New test.
Signed-off-by: Xionghu Luo <xionghuluo@tencent.com>
---
gcc/gimple-if-to-switch.cc | 2 +-
.../gcc.dg/tree-ssa/if-to-switch-11.c | 28 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index 5dcfe5b77e0..f7b0b02628b 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -389,7 +389,7 @@ find_conditions (basic_block bb,
if (cond == NULL)
return;
- if (!no_side_effect_bb (bb))
+ if (!conditions_in_bbs->is_empty () && !no_side_effect_bb (bb))
return;
tree lhs = gimple_cond_lhs (cond);
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c
new file mode 100644
index 00000000000..3dffee04812
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-iftoswitch-optimized" } */
+
+struct f {
+ int len;
+ int arr[4];
+};
+
+int
+test (struct f const *const f)
+{
+ if (f->arr[3] == 1) {
+ return 12;
+ } else if (f->arr[3] == 2) {
+ return 27;
+ } else if (f->arr[3] == 3) {
+ return 38;
+ } else if (f->arr[3] == 4) {
+ return 18;
+ } else if (f->arr[3] == 5) {
+ return 58;
+ } else if (f->arr[3] == 6) {
+ return 68;
+ }
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump "Canonical GIMPLE case clusters: 1 2 3 4 5 6" "iftoswitch" } } */
--
2.35.1.415.g9a52fd993e
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 3:05 [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740] xionghuluo(罗雄虎)
@ 2022-06-21 3:44 ` Xionghu Luo
2022-06-21 7:28 ` Martin Liška
2022-06-21 7:33 ` Richard Biener
1 sibling, 1 reply; 10+ messages in thread
From: Xionghu Luo @ 2022-06-21 3:44 UTC (permalink / raw)
To: xionghuluo(罗雄虎), gcc-patches
Correct the format...
test2:
.LFB0:
.cfi_startproc
xorl %edx, %edx
cmpl $3, (%rdi)
jle .L1
movl 16(%rdi), %eax
cmpl $1, %eax
je .L4
subl $2, %eax
cmpl $4, %eax
ja .L1
movl CSWTCH.1(,%rax,4), %edx
.L1:
movl %edx, %eax
ret
.p2align 4,,10
.p2align 3
.L4:
movl $12, %edx
jmp .L1
.cfi_endproc
.LFE0:
.size test2, .-test2
.section .rodata
.align 16
.type CSWTCH.1, @object
.size CSWTCH.1, 20
CSWTCH.1:
.long 27
.long 38
.long 18
.long 58
.long 68
With the patch attatched:
test2:
.LFB0:
.cfi_startproc
xorl %edx, %edx
cmpl $3, (%rdi)
jle .L1
movl 16(%rdi), %eax
subl $1, %eax
cmpl $5, %eax
jbe .L6
.L1:
movl %edx, %eax
ret
.p2align 4,,10
.p2align 3
.L6:
movl CSWTCH.1(,%rax,4), %edx
movl %edx, %eax
ret
.cfi_endproc
.LFE0:
.size test2, .-test2
.section .rodata
.align 16
.type CSWTCH.1, @object
.size CSWTCH.1, 24
CSWTCH.1:
.long 12
.long 27
.long 38
.long 18
.long 58
.long 68
On 2022/6/21 11:05, xionghuluo(罗雄虎) via Gcc-patches wrote:
> Current GCC generates:
>
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> cmpl $1, %eax
> je .L4
> subl $2, %eax
> cmpl $4, %eax
> ja .L1
> movl CSWTCH.1(,%rax,4), %edx
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L4:
> movl $12, %edx
> jmp .L1
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 20
> CSWTCH.1:
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
>
>
> With the patch attatched:
>
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> subl $1, %eax
> cmpl $5, %eax
> jbe .L6
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L6:
> movl CSWTCH.1(,%rax,4), %edx
> movl %edx, %eax
> ret
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 24
> CSWTCH.1:
> .long 12
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 3:44 ` Xionghu Luo
@ 2022-06-21 7:28 ` Martin Liška
2022-06-21 7:33 ` Xi Ruoyao
0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-06-21 7:28 UTC (permalink / raw)
To: Xionghu Luo, xionghuluo(罗雄虎), gcc-patches
On 6/21/22 05:44, Xionghu Luo via Gcc-patches wrote:
> Correct the format...
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> cmpl $1, %eax
> je .L4
> subl $2, %eax
> cmpl $4, %eax
> ja .L1
> movl CSWTCH.1(,%rax,4), %edx
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L4:
> movl $12, %edx
> jmp .L1
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 20
> CSWTCH.1:
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
>
> With the patch attatched:
>
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> subl $1, %eax
> cmpl $5, %eax
> jbe .L6
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L6:
> movl CSWTCH.1(,%rax,4), %edx
> movl %edx, %eax
> ret
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 24
> CSWTCH.1:
> .long 12
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
>
>
> On 2022/6/21 11:05, xionghuluo(罗雄虎) via Gcc-patches wrote:
>> Current GCC generates:
>>
>>
>> test2:
>> .LFB0:
>> .cfi_startproc
>> xorl %edx, %edx
>> cmpl $3, (%rdi)
>> jle .L1
>> movl 16(%rdi), %eax
>> cmpl $1, %eax
>> je .L4
>> subl $2, %eax
>> cmpl $4, %eax
>> ja .L1
>> movl CSWTCH.1(,%rax,4), %edx
>> .L1:
>> movl %edx, %eax
>> ret
>> .p2align 4,,10
>> .p2align 3
>> .L4:
>> movl $12, %edx
>> jmp .L1
>> .cfi_endproc
>> .LFE0:
>> .size test2, .-test2
>> .section .rodata
>> .align 16
>> .type CSWTCH.1, @object
>> .size CSWTCH.1, 20
>> CSWTCH.1:
>> .long 27
>> .long 38
>> .long 18
>> .long 58
>> .long 68
>>
>>
>>
>>
>> With the patch attatched:
>>
>>
>> test2:
>> .LFB0:
>> .cfi_startproc
>> xorl %edx, %edx
>> cmpl $3, (%rdi)
>> jle .L1
>> movl 16(%rdi), %eax
>> subl $1, %eax
>> cmpl $5, %eax
>> jbe .L6
>> .L1:
>> movl %edx, %eax
>> ret
>> .p2align 4,,10
>> .p2align 3
>> .L6:
>> movl CSWTCH.1(,%rax,4), %edx
>> movl %edx, %eax
>> ret
>> .cfi_endproc
>> .LFE0:
>> .size test2, .-test2
>> .section .rodata
>> .align 16
>> .type CSWTCH.1, @object
>> .size CSWTCH.1, 24
>> CSWTCH.1:
>> .long 12
>> .long 27
>> .long 38
>> .long 18
>> .long 58
>> .long 68
>>
>>
>> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
>
Sorry, but I don't see to which email this replies to?
Can't find a patch.
Martin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 3:05 [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740] xionghuluo(罗雄虎)
2022-06-21 3:44 ` Xionghu Luo
@ 2022-06-21 7:33 ` Richard Biener
2022-06-21 10:05 ` Xionghu Luo
1 sibling, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-06-21 7:33 UTC (permalink / raw)
To: xionghuluo(罗雄虎); +Cc: gcc-patches
On Tue, Jun 21, 2022 at 5:06 AM xionghuluo(罗雄虎) via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Current GCC generates:
>
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> cmpl $1, %eax
> je .L4
> subl $2, %eax
> cmpl $4, %eax
> ja .L1
> movl CSWTCH.1(,%rax,4), %edx
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L4:
> movl $12, %edx
> jmp .L1
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 20
> CSWTCH.1:
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
>
>
> With the patch attatched:
>
>
> test2:
> .LFB0:
> .cfi_startproc
> xorl %edx, %edx
> cmpl $3, (%rdi)
> jle .L1
> movl 16(%rdi), %eax
> subl $1, %eax
> cmpl $5, %eax
> jbe .L6
> .L1:
> movl %edx, %eax
> ret
> .p2align 4,,10
> .p2align 3
> .L6:
> movl CSWTCH.1(,%rax,4), %edx
> movl %edx, %eax
> ret
> .cfi_endproc
> .LFE0:
> .size test2, .-test2
> .section .rodata
> .align 16
> .type CSWTCH.1, @object
> .size CSWTCH.1, 24
> CSWTCH.1:
> .long 12
> .long 27
> .long 38
> .long 18
> .long 58
> .long 68
>
>
> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
OK if you add a comment that an empty conditions_in_bbs indicates we are
processing the first basic-block (that's not obvious to me).
Thanks,
Richard.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 7:28 ` Martin Liška
@ 2022-06-21 7:33 ` Xi Ruoyao
2022-06-21 7:42 ` Martin Liška
0 siblings, 1 reply; 10+ messages in thread
From: Xi Ruoyao @ 2022-06-21 7:33 UTC (permalink / raw)
To: Martin Li�0�8ka, gcc-patches
On Tue, 2022-06-21 at 09:28 +0200, Martin Liška wrote:
> Sorry, but I don't see to which email this replies to?
> Can't find a patch.
https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596913.html
The patch is an attachment:
https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220621/dbb112d2/attachment-0001.obj
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 7:33 ` Xi Ruoyao
@ 2022-06-21 7:42 ` Martin Liška
2022-06-21 10:08 ` Xionghu Luo
0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-06-21 7:42 UTC (permalink / raw)
To: Xi Ruoyao, gcc-patches
On 6/21/22 09:33, Xi Ruoyao wrote:
> On Tue, 2022-06-21 at 09:28 +0200, Martin Liška wrote:
>
>> Sorry, but I don't see to which email this replies to?
>> Can't find a patch.
>
> https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596913.html
Hm, interesting. It means Thunderbird can't deal with the email format
and I can't see any attachment in the email.
Martin
>
> The patch is an attachment:
>
> https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220621/dbb112d2/attachment-0001.obj
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 7:33 ` Richard Biener
@ 2022-06-21 10:05 ` Xionghu Luo
2022-06-21 12:08 ` Richard Biener
0 siblings, 1 reply; 10+ messages in thread
From: Xionghu Luo @ 2022-06-21 10:05 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On 2022/6/21 15:33, Richard Biener via Gcc-patches wrote:
> On Tue, Jun 21, 2022 at 5:06 AM xionghuluo(罗雄虎) via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>>
>> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
>
> OK if you add a comment that an empty conditions_in_bbs indicates we are
> processing the first basic-block (that's not obvious to me).
>
Thanks. Committed in r13-1184, I assume this doesn't need backport?
Thanks,
Xionghu
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 7:42 ` Martin Liška
@ 2022-06-21 10:08 ` Xionghu Luo
0 siblings, 0 replies; 10+ messages in thread
From: Xionghu Luo @ 2022-06-21 10:08 UTC (permalink / raw)
To: Martin Liška, Xi Ruoyao, gcc-patches
On 2022/6/21 15:42, Martin Liška wrote:
> On 6/21/22 09:33, Xi Ruoyao wrote:
>> On Tue, 2022-06-21 at 09:28 +0200, Martin Liška wrote:
>>
>>> Sorry, but I don't see to which email this replies to?
>>> Can't find a patch.
>>
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596913.html
>
> Hm, interesting. It means Thunderbird can't deal with the email format
> and I can't see any attachment in the email.
It was sent by outlook, seems not work well with thunderbird...
>
> Martin
>
>>
>> The patch is an attachment:
>>
>> https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220621/dbb112d2/attachment-0001.obj
>>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 10:05 ` Xionghu Luo
@ 2022-06-21 12:08 ` Richard Biener
2022-06-29 12:01 ` Martin Liška
0 siblings, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-06-21 12:08 UTC (permalink / raw)
To: Xionghu Luo; +Cc: gcc-patches
On Tue, Jun 21, 2022 at 12:05 PM Xionghu Luo <yinyuefengyi@gmail.com> wrote:
>
>
>
> On 2022/6/21 15:33, Richard Biener via Gcc-patches wrote:
> > On Tue, Jun 21, 2022 at 5:06 AM xionghuluo(罗雄虎) via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> >>
> >>
> >> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
> >
> > OK if you add a comment that an empty conditions_in_bbs indicates we are
> > processing the first basic-block (that's not obvious to me).
> >
>
>
> Thanks. Committed in r13-1184, I assume this doesn't need backport?
No, it's not a regression.
Richard.
> Thanks,
> Xionghu
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
2022-06-21 12:08 ` Richard Biener
@ 2022-06-29 12:01 ` Martin Liška
0 siblings, 0 replies; 10+ messages in thread
From: Martin Liška @ 2022-06-29 12:01 UTC (permalink / raw)
To: Richard Biener, Xionghu Luo; +Cc: gcc-patches
On 6/21/22 14:08, Richard Biener via Gcc-patches wrote:
> On Tue, Jun 21, 2022 at 12:05 PM Xionghu Luo <yinyuefengyi@gmail.com> wrote:
>>
>>
>>
>> On 2022/6/21 15:33, Richard Biener via Gcc-patches wrote:
>>> On Tue, Jun 21, 2022 at 5:06 AM xionghuluo(罗雄虎) via Gcc-patches
>>> <gcc-patches@gcc.gnu.org> wrote:
>>>>
>>>>
>>>> Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master?
>>>
>>> OK if you add a comment that an empty conditions_in_bbs indicates we are
>>> processing the first basic-block (that's not obvious to me).
>>>
>>
>>
>> Thanks. Committed in r13-1184, I assume this doesn't need backport?
>
> No, it's not a regression.
>
> Richard.
>
>> Thanks,
>> Xionghu
Caused https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106126
Martin
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-06-29 12:01 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 3:05 [PATCH] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740] xionghuluo(罗雄虎)
2022-06-21 3:44 ` Xionghu Luo
2022-06-21 7:28 ` Martin Liška
2022-06-21 7:33 ` Xi Ruoyao
2022-06-21 7:42 ` Martin Liška
2022-06-21 10:08 ` Xionghu Luo
2022-06-21 7:33 ` Richard Biener
2022-06-21 10:05 ` Xionghu Luo
2022-06-21 12:08 ` Richard Biener
2022-06-29 12:01 ` Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).