You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that for this function the %tmp.4 load is redundant with the loads of X or
Y. It would be better to select one of those load's values.
void %Z5test2RiS(int* %x, int* %y) {
entry:
%tmp.0 = alloca int
%tmp.2 = load int* %x
store int %tmp.2, int* %tmp.0
%tmp.3.i = load int* %y
%tmp.4.i = setlt int %tmp.2, %tmp.3.i
%retval.i = select bool %tmp.4.i, int* %y, int* %tmp.0
%tmp.6 = load int* %retval.i
store int %tmp.6, int* %y
ret void
}
This is even worse. Here we are doing the same thing, selecting the address of
Y or the tmp. Because we need it's address, we are not able to register promote
the tmp, leaving it as an alloca. :(
We should transform these selects into selects of the value not of the pointer
when safe.
-Chris
The text was updated successfully, but these errors were encountered:
Note that the trick to this bug is the whole "when safe" bit. In particular, we
can only turn "*(cond ? P1 : P2)" into "(cond ? *P1 : *P2)" when we know it's
safe to dereference P1 and P2.
Extended Description
Consider this C++ testcase:
#include
void test1(int &x, int &y) {
x = std::min(x,y);
}
void test2(int &x, int &y) {
int tmp = x;
y = std::max(tmp,y);
}
We're currently compiling this into:
void %Z5test1RiS(int* %x, int* %y) {
entry:
%tmp.1.i = load int* %y
%tmp.3.i = load int* %x
%tmp.4.i = setlt int %tmp.1.i, %tmp.3.i
%retval.i = select bool %tmp.4.i, int* %y, int* %x
%tmp.4 = load int* %retval.i
store int %tmp.4, int* %x
ret void
}
Note that for this function the %tmp.4 load is redundant with the loads of X or
Y. It would be better to select one of those load's values.
void %Z5test2RiS(int* %x, int* %y) {
entry:
%tmp.0 = alloca int
%tmp.2 = load int* %x
store int %tmp.2, int* %tmp.0
%tmp.3.i = load int* %y
%tmp.4.i = setlt int %tmp.2, %tmp.3.i
%retval.i = select bool %tmp.4.i, int* %y, int* %tmp.0
%tmp.6 = load int* %retval.i
store int %tmp.6, int* %y
ret void
}
This is even worse. Here we are doing the same thing, selecting the address of
Y or the tmp. Because we need it's address, we are not able to register promote
the tmp, leaving it as an alloca. :(
We should transform these selects into selects of the value not of the pointer
when safe.
-Chris
The text was updated successfully, but these errors were encountered: