[PATCH] D46193: [LSR] Skip LSR if the cost of input is cheaper than LSR's solution

Krzysztof Parzyszek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 9 10:50:22 PDT 2018


kparzysz added a comment.

Here's a testcase where LSR generates code that it worse than the original (on Hexagon):

  #include <stdint.h>
  
  typedef struct {
    int32_t X, Y;
    int32_t *Ptr;
  } S;
  
  int foo(S* Data, int32_t Off, int32_t Idx, int32_t *Out) {
    int32_t Col = Idx;
    if (Off >= Data->X)
      return 5;
  
    while (Col >= Data->Y)
      Col -= Data->Y;
  
    *Out = *(Data->Ptr + Col + Data->Y * Off);
    return 0;
  }

Compile it with `clang -target hexagon -O3`. The code you added eventually punts (`FormInputLSRUseAndFormula` returns false), and LSR proceeds to do its thing. I did some analysis, and the problem is with  `%add.ptr = getelementptr inbounds i32, i32* %2, i32 %Col.0`. This is not an "address use", since it goes into another GEP. It exists in the original source, but LSR never looks at it. Your code does and that makes it exit early. Maybe you should restrict the uses you look at to the same ones that LSR starts with?


https://reviews.llvm.org/D46193





More information about the llvm-commits mailing list