-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
| Bugzilla Link | 863 |
| Resolution | FIXED |
| Resolved on | Feb 22, 2010 12:42 |
| Version | 1.0 |
| OS | All |
| CC | @nlewycky |
Extended Description
Consider this testcase:
int foo(int X, int Y, int Z, int* P1, int* P2, int* P3, int* P4) {
int i;
for (i = 0; i != 1000; ++i) {
int t = *P3;
int s = *P4;
P1 = i4+t+s;
P2 = i4+t+s;
}
}
The "t+s" expression is loop variant (because the loads can't be hoisted), but common between the two
expression uses (the stores to *P1 and *P2).
LSR currently emits:
%tmp = load int* %P3 ; <int> [#uses=1]
%tmp = cast int %tmp to uint ; <uint> [#uses=2]
%tmp2 = load int* %P4 ; <int> [#uses=1]
%tmp2 = cast int %tmp2 to uint ; <uint> [#uses=2]
..
%tmp. = add uint %tmp, %tmp2 ; [#uses=1]
%tmp.2 = add uint %tmp., %iv.1 ; [#uses=1]
%tmp.2 = cast uint %tmp.2 to int ; [#uses=1]
store int %tmp.2, int* %P1
..
%tmp.3 = add uint %tmp, %tmp2 ; [#uses=1]
%tmp.4 = add uint %tmp.3, %iv.1 ; [#uses=1]
%tmp.4 = cast uint %tmp.4 to int ; [#uses=1]
store int %tmp.4, int* %P2
Note that both adds and the cast are exact subexpressions between the two stores (because they both
happen to store the same thing). LSR should not insert trivially redundant expressions like this.
In this specific case, things work out okay, because these expressions are CSE'd in the selection dag.
Unfortunately, this CSE only happens if the uses are in the same BB.
-Chris