[LLVMbugs] [Bug 863] NEW: LSR should CSE expression it inserts into loops.

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Aug 2 23:12:38 PDT 2006


http://llvm.org/bugs/show_bug.cgi?id=863

           Summary: LSR should CSE expression it inserts into loops.
           Product: libraries
           Version: 1.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sabre at nondot.org
                CC: natebegeman at mac.com


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 = i*4+t+s;
    *P2 = i*4+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            ; <uint> [#uses=1]
        %tmp.2 = add uint %tmp., %iv.1          ; <uint> [#uses=1]
        %tmp.2 = cast uint %tmp.2 to int                ; <int> [#uses=1]
        store int %tmp.2, int* %P1
..
        %tmp.3 = add uint %tmp, %tmp2           ; <uint> [#uses=1]
        %tmp.4 = add uint %tmp.3, %iv.1         ; <uint> [#uses=1]
        %tmp.4 = cast uint %tmp.4 to int                ; <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



------- 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