[PATCH] [MemCpyOpt] Turn memcpy from just-memset'd source into memset.

Ahmed Bougacha ahmed.bougacha at gmail.com
Tue May 12 14:49:35 PDT 2015


REPOSITORY
  rL LLVM

================
Comment at: lib/Transforms/Scalar/MemCpyOptimizer.cpp:931
@@ -901,1 +930,3 @@
+}
+
 /// processMemCpy - perform simplification of memcpy's.  If we have memcpy A
----------------
dberlin wrote:
> So, this looks like a valid optimization, and in fact, i expect things like GVN would like this form better than the original.
> 
> But I am curious how often it actually happens.
> 
> Do you have real programs where this triggers?
> 
>From clang, I don't think it happens very often.

I saw this on C++ move constructors implemented in terms of std::swap.  For instance:


```
#include <string>
#include <utility>

struct A {
  std::string a;
  A(A &&other);
};

A::A(A &&other)  {
  std::swap(a, other.a);
}
```

Which I think is a controversial idiom in the C++ world, but still gets written ;)
It's also easy to have an artificial testcase:


```
void bar(int *);

struct B {
  int b[100];
  B() : b() {}
};

void foo() {
  B x;
  B y = x;
  bar(x.b);
  bar(y.b);
}
```

But I can't say I've seen that one (not that I looked; perhaps I should).

http://reviews.llvm.org/D9682

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list