summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp15
-rw-r--r--llvm/test/Transforms/MergeFunc/alloca.ll42
2 files changed, 41 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index d68c05010d7..63e610cc258 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -921,15 +921,6 @@ int FunctionComparator::cmpOperations(const Instruction *L,
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) {
@@ -939,6 +930,12 @@ int FunctionComparator::cmpOperations(const Instruction *L,
}
// Check special state that is a part of some instructions.
+ if (const AllocaInst *AI = dyn_cast<AllocaInst>(L)) {
+ if (int Res = cmpTypes(AI->getAllocatedType(),
+ cast<AllocaInst>(R)->getAllocatedType()))
+ return Res;
+ return cmpNumbers(AI->getAlignment(), cast<AllocaInst>(R)->getAlignment());
+ }
if (const LoadInst *LI = dyn_cast<LoadInst>(L)) {
if (int Res = cmpNumbers(LI->isVolatile(), cast<LoadInst>(R)->isVolatile()))
return Res;
diff --git a/llvm/test/Transforms/MergeFunc/alloca.ll b/llvm/test/Transforms/MergeFunc/alloca.ll
index d9f66d0911d..165fc68365b 100644
--- a/llvm/test/Transforms/MergeFunc/alloca.ll
+++ b/llvm/test/Transforms/MergeFunc/alloca.ll
@@ -1,14 +1,18 @@
; RUN: opt -mergefunc -S < %s | FileCheck %s
-;; Make sure that two different sized allocas are not treated as equal.
+;; Make sure that two different 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 }
+%kv3 = type { i64, i64 }
+; Size difference.
-define void @a(i8 *%f) {
+; CHECK-LABEL: define void @size1
+; CHECK-NOT: call void @
+define void @size1(i8 *%f) {
%v = alloca %kv1, align 8
%f_2 = bitcast i8* %f to void (%kv1 *)*
call void %f_2(%kv1 * %v)
@@ -18,11 +22,9 @@ define void @a(i8 *%f) {
ret void
}
-; CHECK-LABEL: define void @b
-; CHECK-NOT: call @a
-; CHECK: ret
-
-define void @b(i8 *%f) {
+; CHECK-LABEL: define void @size2
+; CHECK-NOT: call void @
+define void @size2(i8 *%f) {
%v = alloca %kv2, align 8
%f_2 = bitcast i8* %f to void (%kv2 *)*
call void %f_2(%kv2 * %v)
@@ -31,3 +33,29 @@ define void @b(i8 *%f) {
call void %f_2(%kv2 * %v)
ret void
}
+
+; Alignment difference.
+
+; CHECK-LABEL: define void @align1
+; CHECK-NOT: call void @
+define void @align1(i8 *%f) {
+ %v = alloca %kv3, align 8
+ %f_2 = bitcast i8* %f to void (%kv3 *)*
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ ret void
+}
+
+; CHECK-LABEL: define void @align2
+; CHECK-NOT: call void @
+define void @align2(i8 *%f) {
+ %v = alloca %kv3, align 16
+ %f_2 = bitcast i8* %f to void (%kv3 *)*
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ call void %f_2(%kv3 * %v)
+ ret void
+}
OpenPOWER on IntegriCloud