[PATCH] D15923: Promote aggregate store to memset when possible
Amaury SECHET via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 6 05:59:41 PST 2016
deadalnix created this revision.
deadalnix added reviewers: craig.topper, spatel, dexonsmith, Prazek, chandlerc, joker.eph, majnemer.
deadalnix added a subscriber: llvm-commits.
As per title. This will allow the optimizer to pick up on it.
http://reviews.llvm.org/D15923
Files:
lib/Transforms/Scalar/MemCpyOptimizer.cpp
test/Transforms/MemCpyOpt/fca2memcpy.ll
Index: test/Transforms/MemCpyOpt/fca2memcpy.ll
===================================================================
--- test/Transforms/MemCpyOpt/fca2memcpy.ll
+++ test/Transforms/MemCpyOpt/fca2memcpy.ll
@@ -37,8 +37,10 @@
define void @destroysrc(%S* %src, %S* %dst) {
; CHECK-LABEL: destroysrc
-; CHECK-NOT: call
-; CHECK: ret void
+; CHECK: load %S, %S* %src
+; CHECK: call void @llvm.memset.p0i8.i64
+; CHECK-NEXT: store %S %1, %S* %dst
+; CHECK-NEXT: ret void
%1 = load %S, %S* %src
store %S zeroinitializer, %S* %src
store %S %1, %S* %dst
@@ -49,7 +51,7 @@
; CHECK-LABEL: destroynoaliassrc
; CHECK-NOT: load
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
-; CHECK-NEXT: store %S zeroinitializer, %S* %src
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64
; CHECK-NEXT: ret void
%1 = load %S, %S* %src
store %S zeroinitializer, %S* %src
Index: lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -534,7 +534,6 @@
for (; I != E; ++I) {
MemoryLocation StoreLoc = MemoryLocation::get(SI);
if (AA.getModRefInfo(&*I, StoreLoc) != MRI_NoModRef) {
- DEBUG(dbgs() << "Alias " << *I << "\n");
P = nullptr;
break;
}
@@ -628,13 +627,36 @@
// Ensure that the value being stored is something that can be memset'able a
// byte at a time like "0" or "-1" or any width, as well as things like
// 0xA0A0A0A0 and 0.0.
- if (Value *ByteVal = isBytewiseValue(SI->getOperand(0)))
+ auto *V = SI->getOperand(0);
+ if (Value *ByteVal = isBytewiseValue(V)) {
if (Instruction *I = tryMergingIntoMemset(SI, SI->getPointerOperand(),
ByteVal)) {
BBI = I->getIterator(); // Don't invalidate iterator.
return true;
}
+ auto *T = V->getType();
+ if (T->isAggregateType()) {
+ uint64_t Size = DL.getTypeStoreSize(T);
+ unsigned Align = SI->getAlignment();
+ if (!Align)
+ Align = DL.getABITypeAlignment(T);
+ IRBuilder<> Builder(SI);
+ auto *M = Builder.CreateMemSet(SI->getPointerOperand(), ByteVal,
+ Size, Align, SI->isVolatile());
+
+ DEBUG(dbgs() << "Promoting " << *SI << " to " << *M << "\n");
+
+ MD->removeInstruction(SI);
+ SI->eraseFromParent();
+ NumMemSetInfer++;
+
+ // Make sure we do not invalidate the iterator.
+ BBI = M->getIterator();
+ return true;
+ }
+ }
+
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15923.44112.patch
Type: text/x-patch
Size: 2636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160106/04d2d3c9/attachment.bin>
More information about the llvm-commits
mailing list