public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/54491] New: interval membership optimization @ 2012-09-05 13:05 neleai at seznam dot cz 2012-09-05 14:22 ` [Bug tree-optimization/54491] " rguenth at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: neleai at seznam dot cz @ 2012-09-05 13:05 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 Bug #: 54491 Summary: interval membership optimization Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: neleai@seznam.cz A common optimization to test range membership b \in [c,d] is to use integer overflow as in function range below. gcc does this optimization when both c and d are constants. However inlining disables this optimization. Same optimization can be automatically applied for c arbitrary expression and d=c+positive_constant unsigned int range(unsigned int b,unsigned int c){ if (b-c<=42) return c; return b; } unsigned int foo(unsigned int b,unsigned int c){ if (c<=b && b <=42+c) return c; return b; } unsigned int bar(unsigned int b){ return foo(b,42); } unsigned int baz(unsigned int b){ if (42<=b && b<=84) return 42; return b; } .file "a.c" .text .p2align 4,,15 .globl range .type range, @function range: .LFB0: .cfi_startproc movl %edi, %eax subl %esi, %eax cmpl $42, %eax movl %esi, %eax cmova %edi, %eax ret .cfi_endproc .LFE0: .size range, .-range .p2align 4,,15 .globl foo .type foo, @function foo: .LFB1: .cfi_startproc cmpl %edi, %esi movl %edi, %eax ja .L5 leal 42(%rsi), %edx cmpl %edx, %edi cmovbe %esi, %eax .L5: rep; ret .cfi_endproc .LFE1: .size foo, .-foo .p2align 4,,15 .globl bar .type bar, @function bar: .LFB2: .cfi_startproc cmpl $41, %edi movl %edi, %eax jbe .L10 cmpl $85, %edi movl $42, %edx cmovb %edx, %eax .L10: rep; ret .cfi_endproc .LFE2: .size bar, .-bar .p2align 4,,15 .globl baz .type baz, @function baz: .LFB3: .cfi_startproc leal -42(%rdi), %edx movl $42, %eax cmpl $42, %edx cmova %edi, %eax ret .cfi_endproc .LFE3: .size baz, .-baz .ident "GCC: (Debian 20120820-1) 4.8.0 20120820 (experimental) [trunk revision 190537]" .section .note.GNU-stack,"",@progbits ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/54491] interval membership optimization 2012-09-05 13:05 [Bug c/54491] New: interval membership optimization neleai at seznam dot cz @ 2012-09-05 14:22 ` rguenth at gcc dot gnu.org 2012-09-05 14:55 ` jakub at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: rguenth at gcc dot gnu.org @ 2012-09-05 14:22 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2012-09-05 Component|c |tree-optimization Ever Confirmed|0 |1 --- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-09-05 14:21:47 UTC --- You are basically requesting 12 < a < 32 to be converted to (unsigned) a - 12 < 20, something fold does but not forwprop or ifcombine. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/54491] interval membership optimization 2012-09-05 13:05 [Bug c/54491] New: interval membership optimization neleai at seznam dot cz 2012-09-05 14:22 ` [Bug tree-optimization/54491] " rguenth at gcc dot gnu.org @ 2012-09-05 14:55 ` jakub at gcc dot gnu.org 2012-09-05 15:09 ` jakub at gcc dot gnu.org 2012-09-05 17:53 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: jakub at gcc dot gnu.org @ 2012-09-05 14:55 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-05 14:54:50 UTC --- I'm suprised PR46309 doesn't handle this. Will look at it. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/54491] interval membership optimization 2012-09-05 13:05 [Bug c/54491] New: interval membership optimization neleai at seznam dot cz 2012-09-05 14:22 ` [Bug tree-optimization/54491] " rguenth at gcc dot gnu.org 2012-09-05 14:55 ` jakub at gcc dot gnu.org @ 2012-09-05 15:09 ` jakub at gcc dot gnu.org 2012-09-05 17:53 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: jakub at gcc dot gnu.org @ 2012-09-05 15:09 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-05 15:09:18 UTC --- Ah, right, the #c7 from that PR applies here. If you use if ((c<=b) & (b <=42+c)) return c; in foo instead, bar will be optimized by the reassoc pass. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/54491] interval membership optimization 2012-09-05 13:05 [Bug c/54491] New: interval membership optimization neleai at seznam dot cz ` (2 preceding siblings ...) 2012-09-05 15:09 ` jakub at gcc dot gnu.org @ 2012-09-05 17:53 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2012-09-05 17:53 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-09-05 17:52:53 UTC --- > integer overflow Note there is never any integer overflow with unsigned types but always wrapping. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-05 17:53 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-09-05 13:05 [Bug c/54491] New: interval membership optimization neleai at seznam dot cz 2012-09-05 14:22 ` [Bug tree-optimization/54491] " rguenth at gcc dot gnu.org 2012-09-05 14:55 ` jakub at gcc dot gnu.org 2012-09-05 15:09 ` jakub at gcc dot gnu.org 2012-09-05 17:53 ` pinskia at gcc dot gnu.org
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).