* [Bug c++/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
@ 2010-11-05 8:37 ` eidletni at mail dot ru
2010-11-06 18:55 ` svfuerst at gmail dot com
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: eidletni at mail dot ru @ 2010-11-05 8:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #1 from eidletni at mail dot ru 2010-11-05 08:36:58 UTC ---
Created attachment 22290
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22290
c++ code
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
2010-11-05 8:37 ` [Bug c++/46309] " eidletni at mail dot ru
@ 2010-11-06 18:55 ` svfuerst at gmail dot com
2011-09-23 22:54 ` paolo.carlini at oracle dot com
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: svfuerst at gmail dot com @ 2010-11-06 18:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Steven Fuerst <svfuerst at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |svfuerst at gmail dot com
--- Comment #2 from Steven Fuerst <svfuerst at gmail dot com> 2010-11-06 18:55:48 UTC ---
This is even better, for this particular case.
mov 0x4(%esp),%eax
and $-3, %eax
cmp $1, %eax
sete%al
ret
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
2010-11-05 8:37 ` [Bug c++/46309] " eidletni at mail dot ru
2010-11-06 18:55 ` svfuerst at gmail dot com
@ 2011-09-23 22:54 ` paolo.carlini at oracle dot com
2011-09-24 9:57 ` [Bug tree-optimization/46309] " jakub at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 22:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 22:40:32 UTC ---
If anything, doesn't seem a C++ issue... Richard can you have a look?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (2 preceding siblings ...)
2011-09-23 22:54 ` paolo.carlini at oracle dot com
@ 2011-09-24 9:57 ` jakub at gcc dot gnu.org
2011-09-30 15:16 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-09-24 9:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Component|c++ |tree-optimization
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-09-24 08:36:27 UTC ---
With s/bool/int/ we generate identical code for both, without jumps.
Anyway, more important is that we don't seem to optimize the
x == CST1 || x == CST2 where __builtin_popcount (CST1 ^ CST2) == 1
in fold-const.c and don't even optimize range tests if the constants alternate
and, more importantly, don't seem to do anything similar to fold_range_test at
the GIMPLE level.
int
f1 (int a, int b)
{
int v1 = (a == 3);
int v2 = (a == 1);
int v3 = (a == 4);
int v4 = (a == 2);
return v1 || v2 || v3 || v4;
}
int
f2 (int a, int b)
{
int v1 = (a == 1);
int v2 = (a == 2);
int v3 = (a == 3);
int v4 = (a == 4);
return v1 || v2 || v3 || v4;
}
int
f3 (int a, int b)
{
int v1 = (a == 3);
int v2 = (a == 1);
return v1 || v2;
}
int
f4 (int a, int b)
{
int v1 = (a == 1);
int v2 = (a == 2);
return v1 || v2;
}
int
f5 (int a, int b)
{
return a == 3 || a == 1 || a == 4 || a == 2;
}
int
f6 (int a, int b)
{
return a == 1 || a == 2 || a == 3 || a == 4;
}
int
f7 (int a, int b)
{
return a == 3 || a == 1;
}
int
f8 (int a, int b)
{
return a == 1 || a == 2;
}
int
f9 (int a, int b)
{
return a == 3 || a == 1 || a == 2 || a == 4;
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (3 preceding siblings ...)
2011-09-24 9:57 ` [Bug tree-optimization/46309] " jakub at gcc dot gnu.org
@ 2011-09-30 15:16 ` jakub at gcc dot gnu.org
2011-09-30 20:19 ` paolo.carlini at oracle dot com
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-09-30 15:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-09-30 15:00:18 UTC ---
Author: jakub
Date: Fri Sep 30 15:00:12 2011
New Revision: 179388
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179388
Log:
PR tree-optimization/46309
* fold-const.c (make_range, merge_ranges): Remove prototypes.
(make_range_step): New function.
(make_range): Use it.
* tree.h (make_range_step): New prototypes.
* Makefile.in (tree-ssa-reassoc.o): Depend on $(DIAGNOSTIC_CORE_H).
* tree-ssa-reassoc.c: Include diagnostic-core.h.
(struct range_entry): New type.
(init_range_entry, range_entry_cmp, update_range_test,
optimize_range_tests): New functions.
(reassociate_bb): Call optimize_range_tests.
* gcc.dg/pr46309.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/pr46309.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/Makefile.in
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-reassoc.c
trunk/gcc/tree.h
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (4 preceding siblings ...)
2011-09-30 15:16 ` jakub at gcc dot gnu.org
@ 2011-09-30 20:19 ` paolo.carlini at oracle dot com
2011-09-30 20:28 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-30 20:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011-09-30
Ever Confirmed|0 |1
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-30 20:10:37 UTC ---
Thank for this, Jakub! I'm confirming the issue ;) Shall we close it as fixed
for 4.7.0 or would it make sense to backport something?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (5 preceding siblings ...)
2011-09-30 20:19 ` paolo.carlini at oracle dot com
@ 2011-09-30 20:28 ` jakub at gcc dot gnu.org
2011-09-30 20:48 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-09-30 20:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-09-30 20:18:59 UTC ---
Well, the original issue isn't fully fixed. If the gimplifier decides to split
the conditions into multiple basic blocks, i.e. if it isn't
tmp1 = a == 1;
tmp2 = a == 3;
tmp3 = a == 4;
tmp4 = a == 2;
tmp5 = tmp1 | tmp2;
tmp6 = tmp5 | tmp3;
x = tmp6 | tmp4;
but instead
if (a == 1)
goto <bb X>;
if (a == 3)
goto <bb X>;
if (a == 4)
goto <bb X>;
if (a == 2)
goto <bb X>;
x = 0;
goto <bb Y>;
X:
x = 1;
or similar (e.g. two comparisons BIT_IOR_EXPRed together, then jump), then this
optimization isn't performed.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (6 preceding siblings ...)
2011-09-30 20:28 ` jakub at gcc dot gnu.org
@ 2011-09-30 20:48 ` paolo.carlini at oracle dot com
2011-11-23 1:55 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-30 20:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-30 20:25:14 UTC ---
I see... thanks.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (7 preceding siblings ...)
2011-09-30 20:48 ` paolo.carlini at oracle dot com
@ 2011-11-23 1:55 ` pinskia at gcc dot gnu.org
2012-10-31 8:46 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-23 1:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-11-23 00:58:23 UTC ---
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc1 "Optimizing range tests
a_[0-9]*.D. -.1, 1. and -.2, 2. and -.3, 3. and -.4, 4.[
]* into" 2
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc1 "Optimizing range tests
a_[0-9]*.D. -.1, 1. and -.3, 3.[
]* into" 1
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc1 "Optimizing range tests
a_[0-9]*.D. -.1, 1. and -.2, 2.[
]* into" 1
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc1 "Optimizing range tests
a_[0-9]*.D. -.0, 31. and -.64, 95.[
]* into" 2
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc1 "Optimizing range tests
a_[0-9]*.D. -.128, 159. and -.192, 223.[
]* into" 1
FAIL: gcc.dg/pr46309.c scan-tree-dump-times reassoc2 "Optimizing range tests
D.[0-9]*_[0-9]* -.0, 31. and -.128, 159.[
]* into" 1
On mips64-linux-gnu
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (8 preceding siblings ...)
2011-11-23 1:55 ` pinskia at gcc dot gnu.org
@ 2012-10-31 8:46 ` jakub at gcc dot gnu.org
2012-10-31 8:55 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-31 8:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-31 08:45:36 UTC ---
Author: jakub
Date: Wed Oct 31 08:45:27 2012
New Revision: 193028
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193028
Log:
PR tree-optimization/19105
PR tree-optimization/21643
PR tree-optimization/46309
* tree-ssa-reassoc.c (init_range_entry): Add STMT argument
and use it if EXP is NULL.
(update_range_test): Handle OPCODE equal to ERROR_MARK
and oe->op NULL.
(optimize_range_tests): Likewise.
(final_range_test_p, suitable_cond_bb, no_side_effect_bb, get_ops,
maybe_optimize_range_tests): New functions.
(reassociate_bb): Call maybe_optimize_range_tests if last
stmt of bb is GIMPLE_COND that hasn't been visited yet.
* gcc.dg/pr19105.c: New test.
* gcc.dg/pr21643.c: New test.
* gcc.dg/pr46309-2.c: New test.
* gcc.c-torture/execute/pr46309.c: New test.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr46309.c
trunk/gcc/testsuite/gcc.dg/pr19105.c
trunk/gcc/testsuite/gcc.dg/pr21643.c
trunk/gcc/testsuite/gcc.dg/pr46309-2.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-reassoc.c
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (9 preceding siblings ...)
2012-10-31 8:46 ` jakub at gcc dot gnu.org
@ 2012-10-31 8:55 ` jakub at gcc dot gnu.org
2012-10-31 19:10 ` eidletni at mail dot ru
2012-10-31 22:37 ` rdsandiford at googlemail dot com
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-31 8:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.8.0
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-31 08:54:40 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (10 preceding siblings ...)
2012-10-31 8:55 ` jakub at gcc dot gnu.org
@ 2012-10-31 19:10 ` eidletni at mail dot ru
2012-10-31 22:37 ` rdsandiford at googlemail dot com
12 siblings, 0 replies; 14+ messages in thread
From: eidletni at mail dot ru @ 2012-10-31 19:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
eidletni at mail dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |CLOSED
--- Comment #12 from eidletni at mail dot ru 2012-10-31 19:09:32 UTC ---
Cool, thank you!
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/46309] optimization a==3||a==1
2010-11-05 8:36 [Bug c++/46309] New: optimization a==3||a==1 eidletni at mail dot ru
` (11 preceding siblings ...)
2012-10-31 19:10 ` eidletni at mail dot ru
@ 2012-10-31 22:37 ` rdsandiford at googlemail dot com
12 siblings, 0 replies; 14+ messages in thread
From: rdsandiford at googlemail dot com @ 2012-10-31 22:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
--- Comment #13 from rdsandiford at googlemail dot com <rdsandiford at googlemail dot com> 2012-10-31 22:36:48 UTC ---
"eidletni at mail dot ru" <gcc-bugzilla@gcc.gnu.org> writes:
> Cool, thank you!
+1, thanks Jakub
^ permalink raw reply [flat|nested] 14+ messages in thread