[llvm] r236969 - [InstCombine] Canonicalize single element array store

David Majnemer david.majnemer at gmail.com
Sun May 10 22:04:27 PDT 2015


Author: majnemer
Date: Mon May 11 00:04:27 2015
New Revision: 236969

URL: http://llvm.org/viewvc/llvm-project?rev=236969&view=rev
Log:
[InstCombine] Canonicalize single element array store

Use the element type instead of the aggregate type.

Differential Revision: http://reviews.llvm.org/D9591

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=236969&r1=236968&r2=236969&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Mon May 11 00:04:27 2015
@@ -880,6 +880,15 @@ static bool unpackStoreToAggregate(InstC
     }
   }
 
+  if (auto *AT = dyn_cast<ArrayType>(T)) {
+    // If the array only have one element, we unpack.
+    if (AT->getNumElements() == 1) {
+      V = IC.Builder->CreateExtractValue(V, 0);
+      combineStoreToNewValue(IC, SI, V);
+      return true;
+    }
+  }
+
   return false;
 }
 

Modified: llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll?rev=236969&r1=236968&r2=236969&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll Mon May 11 00:04:27 2015
@@ -32,6 +32,26 @@ body:
   ret void
 }
 
+define void @storeArrayOfA() {
+body:
+  %0 = tail call i8* @allocmemory(i64 32)
+  %1 = bitcast i8* %0 to [1 x %A]*
+; CHECK-LABEL: storeStructOfA
+; CHECK: store %A__vtbl* @A__vtblZ
+  store [1 x %A] [%A { %A__vtbl* @A__vtblZ }], [1 x %A]* %1, align 8
+  ret void
+}
+
+define void @storeStructOfArrayOfA() {
+body:
+  %0 = tail call i8* @allocmemory(i64 32)
+  %1 = bitcast i8* %0 to { [1 x %A] }*
+; CHECK-LABEL: storeStructOfArrayOfA
+; CHECK: store %A__vtbl* @A__vtblZ
+  store { [1 x %A] } { [1 x %A] [%A { %A__vtbl* @A__vtblZ }] }, { [1 x %A] }* %1, align 8
+  ret void
+}
+
 define %A @loadA() {
 body:
   %0 = tail call i8* @allocmemory(i64 32)





More information about the llvm-commits mailing list