Index: lib/Transforms/IPO/MergeFunctions.cpp =================================================================== --- lib/Transforms/IPO/MergeFunctions.cpp +++ lib/Transforms/IPO/MergeFunctions.cpp @@ -1082,11 +1082,8 @@ Value *OpR = InstR->getOperand(i); if (int Res = cmpValues(OpL, OpR)) return Res; - if (int Res = cmpNumbers(OpL->getValueID(), OpR->getValueID())) - return Res; - // TODO: Already checked in cmpOperation - if (int Res = cmpTypes(OpL->getType(), OpR->getType())) - return Res; + // cmpValues should ensure this is true. + assert(cmpTypes(OpL->getType(), OpR->getType()) == 0); } } Index: test/Transforms/MergeFunc/merge-const-ptr-and-int.ll =================================================================== --- /dev/null +++ test/Transforms/MergeFunc/merge-const-ptr-and-int.ll @@ -0,0 +1,83 @@ +; RUN: opt -mergefunc -S < %s | FileCheck %s +; RUN: opt -mergefunc -S < %s | FileCheck -check-prefix=CHECKNOT %s +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" + +; Afunc and Bfunc differ only in that one returns i64, the other a pointer. +; These should be merged. +define internal i64 @Afunc(i32* %P, i32* %Q) { + store i32 4, i32* %P + store i32 6, i32* %Q + ret i64 0 +} + +define internal i64* @Bfunc(i32* %P, i32* %Q) { + store i32 4, i32* %P + store i32 6, i32* %Q + ret i64* null +} + +define void @Cfunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define void @Cfunc +; CHECK-NEXT: @Afunc +; CHECK-NEXT: @Afunc +; CHECK-NEXT: @Afunc +; CHECK-NEXT: ret void + call i64 @Afunc(i32* %P, i32* %Q) + call i64* @Bfunc(i32* %P, i32* %Q) + call i64 @Afunc(i32* %Q, i32* %P) + ret void +} + + +; These should not be merged, as the datalayout says a pointer is 64 bits. No +; sext/zext is specified, so these functions could lower differently. +define internal i32 @Ffunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define internal i32 @Ffunc +; CHECK-NEXT: store +; CHECK-NEXT: store +; CHECK-NEXT: ret + store i32 1, i32* %P + store i32 3, i32* %Q + ret i32 0 +} + +define internal i64* @Gfunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define internal i64* @Gfunc +; CHECK-NEXT: store +; CHECK-NEXT: store +; CHECK-NEXT: ret + store i32 1, i32* %P + store i32 3, i32* %Q + ret i64* null +} + +; These should not be merged either, as 1 != 0. + +define internal i64 @Ifunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define internal i64 @Ifunc + store i32 10, i32* %P + store i32 10, i32* %Q + ret i64 1 +} + +define internal i64* @Jfunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define internal i64* @Jfunc + store i32 10, i32* %P + store i32 10, i32* %Q + ret i64* null +} + +; Merging should still work, even if the values are wrapped in a vector. +define internal <2 x i64> @Mfunc(i32* %P, i32* %Q) { +; CHECK-LABEL: define internal <2 x i64> @Mfunc + store i32 1, i32* %P + store i32 1, i32* %Q + ret <2 x i64> +} + +define internal <2 x i64*> @Nfunc(i32* %P, i32* %Q) { +; CHECKNOT-NOT: @Nfunc + store i32 1, i32* %P + store i32 1, i32* %Q + ret <2 x i64*> +}