From 414a781256d8e2c7dd9be5f8d47c2341571903af Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Tue, 12 May 2015 21:42:22 +0000 Subject: [PATCH] MergeFunctions: Two different sized allocas are *not* the same git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237193 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/MergeFunctions.cpp | 9 ++++++++ test/Transforms/MergeFunc/alloca.ll | 33 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/Transforms/MergeFunc/alloca.ll diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index 396ab9ba505..91a5eefca17 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -719,6 +719,15 @@ int FunctionComparator::cmpOperations(const Instruction *L, R->getRawSubclassOptionalData())) return Res; + if (const AllocaInst *AI = dyn_cast(L)) { + if (int Res = cmpTypes(AI->getAllocatedType(), + cast(R)->getAllocatedType())) + return Res; + if (int Res = + cmpNumbers(AI->getAlignment(), cast(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) { diff --git a/test/Transforms/MergeFunc/alloca.ll b/test/Transforms/MergeFunc/alloca.ll new file mode 100644 index 00000000000..d9f66d0911d --- /dev/null +++ b/test/Transforms/MergeFunc/alloca.ll @@ -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 +} -- 2.34.1