[llvm] r237193 - MergeFunctions: Two different sized allocas are *not* the same

Arnold Schwaighofer aschwaighofer at apple.com
Tue May 12 14:42:23 PDT 2015


Author: arnolds
Date: Tue May 12 16:42:22 2015
New Revision: 237193

URL: http://llvm.org/viewvc/llvm-project?rev=237193&view=rev
Log:
MergeFunctions: Two different sized allocas are *not* the same

Added:
    llvm/trunk/test/Transforms/MergeFunc/alloca.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp

Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=237193&r1=237192&r2=237193&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Tue May 12 16:42:22 2015
@@ -719,6 +719,15 @@ int FunctionComparator::cmpOperations(co
                            R->getRawSubclassOptionalData()))
     return Res;
 
+  if (const AllocaInst *AI = dyn_cast<AllocaInst>(L)) {
+    if (int Res = cmpTypes(AI->getAllocatedType(),
+                           cast<AllocaInst>(R)->getAllocatedType()))
+      return Res;
+    if (int Res =
+            cmpNumbers(AI->getAlignment(), cast<AllocaInst>(R)->getAlignment()))
+      return Res;
+  }
+
   // We have two instructions of identical opcode and #operands.  Check to see
   // if all operands are the same type
   for (unsigned i = 0, e = L->getNumOperands(); i != e; ++i) {

Added: llvm/trunk/test/Transforms/MergeFunc/alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeFunc/alloca.ll?rev=237193&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeFunc/alloca.ll (added)
+++ llvm/trunk/test/Transforms/MergeFunc/alloca.ll Tue May 12 16:42:22 2015
@@ -0,0 +1,33 @@
+; RUN: opt -mergefunc -S < %s | FileCheck %s
+
+;; Make sure that two different sized allocas are not treated as equal.
+
+target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
+
+%kv1 = type { i32, i32 }
+%kv2 = type { i8 }
+
+
+define void @a(i8 *%f) {
+  %v = alloca %kv1, align 8
+  %f_2 = bitcast i8* %f to void (%kv1 *)*
+  call void %f_2(%kv1 * %v)
+  call void %f_2(%kv1 * %v)
+  call void %f_2(%kv1 * %v)
+  call void %f_2(%kv1 * %v)
+  ret void
+}
+
+; CHECK-LABEL: define void @b
+; CHECK-NOT: call @a
+; CHECK: ret
+
+define void @b(i8 *%f) {
+  %v = alloca %kv2, align 8
+  %f_2 = bitcast i8* %f to void (%kv2 *)*
+  call void %f_2(%kv2 * %v)
+  call void %f_2(%kv2 * %v)
+  call void %f_2(%kv2 * %v)
+  call void %f_2(%kv2 * %v)
+  ret void
+}





More information about the llvm-commits mailing list