[Bug tree-optimization/58728] New: [missed optimization] == or != comparisons may affect range test optimization.
congh at google dot com
gcc-bugzilla@gcc.gnu.org
Mon Oct 14 20:04:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58728
Bug ID: 58728
Summary: [missed optimization] == or != comparisons may affect
range test optimization.
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: congh at google dot com
Created attachment 31002
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31002&action=edit
Patch
Look at the following code:
int foo(unsigned int n)
{
if (n != 0)
if (n != 1)
if (n != 2)
if (n != 3)
if (n != 4)
return ++n;
return n;
}
Those five comparisons should be able to be merged into one during range test
optimization but they are not. The reason is that GCC checks the phi args of n
after the branch to make sure two false edges of two neighboring ifs define the
same phi arg at the join node (thus guarantees side-effect free). However, the
"vrp" pass replaced the phi arg by the identical value of the original phi arg
deducted from == or != comparisons, hence preventing the range test
optimization.
The same case is in if-combine pass.
I made a patch for this issue which is attached here.
More information about the Gcc-bugs
mailing list