[PATCH] [SROA] Fix for a SROA store widening bug

Gao, Yunzhong yunzhong_gao at playstation.sony.com
Mon Aug 18 12:35:12 PDT 2014


Hi all,

Re: http://reviews.llvm.org/D4933

Sorry, but it seems that Phabricator only sent out the first comment but not my original
patch description to the mailing list. I am copy-pasting the message again here.

[Title] [SROA] Fix for a SROA store widening bug

[Summary]
Hi,

I ran into the following test case which breaks if I compile for x86_64-linux
at -O2 or higher, but works at -O1.

The bug appears to be in the SROA pass where a 12-byte memcpy is replaced with
a 16-byte <4 x float> store, which writes past the boundary of a struct on the
stack. I includes a fix here for review which keeps the memcpy when the memory
transfer size appears to be too large, but I am not very familiar with SROA and
I am not sure if there are other similar cases I should cover.

Any advice will be appreciated,
- Gao

[Test Plan]
To reproduce:
   $ clang -O2 -o a.out test.cpp main.cpp
   $ ./a.out
   (segfault)

   $ clang -O2 -mllvm -use-new-sroa=false test.cpp main.cpp
   $ ./a.out
   1.000000 1.000000 1.000000

The test case includes three files below:
header.h,   test.cpp,    main.cpp

```
// Begin header.h
struct Pixel { float X,Y,Z; };
struct Checker
{
  unsigned result;
  Checker(const Pixel *In)
    : A(*In) { result = helper(); }
private:
  unsigned helper();
  const Pixel A;
};
// End header.h
```

```
// Begin test.cpp
#include "header.h"
#include <x86intrin.h>

__inline__ __attribute__((always_inline))
unsigned inline_test(const Pixel *v)
{
  const float *tmp = &v->X;
  if (_mm_movemask_ps(_mm_loadu_ps(tmp)))
    return 0;
  Checker P(v);
  return P.result;
}

unsigned test(const Pixel* pdata)
{
  const Pixel tmp = pdata[0];
  return inline_test(&tmp);
}
// End test.cpp
```

```
// Begin main.cpp
#include "header.h"
#include <stdio.h>

extern unsigned test(const Pixel* pdata);
unsigned Checker::helper() { return A.X == A.Y; }

int main()
{
  Pixel data = { 1.0f, 1.0f, 1.0f };
  test(&data);
  printf("%f %f %f\n", data.X, data.Y, data.Z);
  return 0;
}
// End main.cpp
```


From:	Yunzhong Gao
To:	Yunzhong Gao
Cc:	benny.kra at gmail.com, llvm-commits at cs.uiuc.edu
Date:	15/08/2014 19:58
Subject:	Re: [PATCH] [SROA] Fix for a SROA store widening bug
Sent by:	llvm-commits-bounces at cs.uiuc.edu

send

http://reviews.llvm.org/D4933

_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list