Bug 20656 - No strength reduction for a simple testcase
Summary: No strength reduction for a simple testcase
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on: 22325
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-27 19:13 UTC by Andrew Pinski
Modified: 2006-02-15 19:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-21 02:15:38


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-03-27 19:13:34 UTC
The following two function should be equivalent:
int f(int offset, int len, int num_bytes)
{
int i;
num_bytes = 0;
for (i = 0; i < len; i++) num_bytes ++;
return num_bytes;
}

int f1(int offset, int len, int num_bytes)
{
  if (len<0)
   return 0;
  return len;
}

Why don't we strength reduce the loop in f?
Then we just need to remove the loop and two functions would be equivalent.

The orginal code which was found in real code (I think java code in classpath):
int f(int offset, int len, int num_bytes)
{
  int i;
  for (i = 0; i < len; i++) num_bytes +=2;
  return num_bytes;
}
int f1(int offset, int len, int num_bytes)
{
  if (len<0)
   return num_bytes;
  return num_bytes+len*2;
}
Comment 1 Andrew Pinski 2005-04-06 18:50:25 UTC
Confirmed.
Comment 2 Hans-Peter Nilsson 2005-11-08 00:30:49 UTC
Seen at test-case reduction also for code of the form:
int i; for (i = 1; i <= shift_size; i++) { }
not producing the same ICE as for:
int i; i = 1 <= shift_size ? shift_size : 1;
(I'll put a pointer here to the complete test-case in due time.)
Comment 3 Hans-Peter Nilsson 2005-11-09 03:45:18 UTC
Referring to comment #2, the test-case for PR 24750 has a few similar loops and
a few other PR references that seems relevant.
Comment 4 Andrew Pinski 2006-02-15 19:14:13 UTC
Fixed on the mainline now (I don't know what by).