[LLVMbugs] [Bug 362] NEW: Icky code generated for std::min/std::max

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Jun 7 17:11:38 PDT 2004


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=362

           Summary: Icky code generated for std::min/std::max
           Product: tools
           Version: 1.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: llvm-g++
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sabre at nondot.org


Consider this C++ testcase:

--------
#include <algorithm>
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



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




More information about the llvm-bugs mailing list