[PATCH] Add support for one element array load in InstCombine

Amaury SECHET deadalnix+llvmreview at gmail.com
Thu May 7 22:17:59 PDT 2015


Hi reames, chandlerc, majnemer, joker.eph, pete,

As per title

http://reviews.llvm.org/D9596

Files:
  lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  test/Transforms/InstCombine/unpack-fca.ll

Index: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -518,6 +518,16 @@
     }
   }
 
+  if (auto *AT = dyn_cast<ArrayType>(T)) {
+    // If the array only have one element, we unpack.
+    if (AT->getNumElements() == 1) {
+      LoadInst *NewLoad = combineLoadToNewType(IC, LI, AT->getElementType(),
+                                               ".unpack");
+      return IC.ReplaceInstUsesWith(LI, IC.Builder->CreateInsertValue(
+        UndefValue::get(T), NewLoad, 0, LI.getName()));
+    }
+  }
+
   return nullptr;
 }
 
Index: test/Transforms/InstCombine/unpack-fca.ll
===================================================================
--- test/Transforms/InstCombine/unpack-fca.ll
+++ test/Transforms/InstCombine/unpack-fca.ll
@@ -55,6 +55,31 @@
   ret { %A } %2
 }
 
+define [1 x %A] @loadArrayOfA() {
+body:
+  %0 = tail call i8* @allocmemory(i64 32)
+  %1 = bitcast i8* %0 to [1 x %A]*
+; CHECK-LABEL: loadArrayOfA
+; CHECK: load %A__vtbl*,
+; CHECK: insertvalue %A undef, %A__vtbl* {{.*}}, 0
+; CHECK: insertvalue [1 x %A] undef, %A {{.*}}, 0
+  %2 = load [1 x %A], [1 x %A]* %1, align 8
+  ret [1 x %A] %2
+}
+
+define { [1 x %A] } @loadStructOfArrayOfA() {
+body:
+  %0 = tail call i8* @allocmemory(i64 32)
+  %1 = bitcast i8* %0 to { [1 x %A] }*
+; CHECK-LABEL: loadStructOfArrayOfA
+; CHECK: load %A__vtbl*,
+; CHECK: insertvalue %A undef, %A__vtbl* {{.*}}, 0
+; CHECK: insertvalue [1 x %A] undef, %A {{.*}}, 0
+; CHECK: insertvalue { [1 x %A] } undef, [1 x %A] {{.*}}, 0
+  %2 = load { [1 x %A] }, { [1 x %A] }* %1, align 8
+  ret { [1 x %A] } %2
+}
+
 define { %A } @structOfA() {
 body:
   %0 = tail call i8* @allocmemory(i64 32)

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9596.25283.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150508/68bfd048/attachment.bin>


More information about the llvm-commits mailing list