From 32d33b59bceec080b40771fc3893f202ccbae1ee Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Mon, 14 Dec 2015 19:11:40 +0000 Subject: [PATCH] Teach MergeFunctions about operand bundles git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255528 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/MergeFunctions.cpp | 31 +++++++++++++++++++++ test/Feature/OperandBundles/merge-func.ll | 34 +++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/Feature/OperandBundles/merge-func.ll diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index fb37bcd42ed..132b5872fbe 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -407,6 +407,7 @@ private: int cmpMem(StringRef L, StringRef R) const; int cmpAttrs(const AttributeSet L, const AttributeSet R) const; int cmpRangeMetadata(const MDNode* L, const MDNode* R) const; + int cmpOperandBundlesSchema(const Instruction *L, const Instruction *R) const; // The two functions undergoing comparison. const Function *FnL, *FnR; @@ -564,6 +565,32 @@ int FunctionComparator::cmpRangeMetadata(const MDNode* L, return 0; } +int FunctionComparator::cmpOperandBundlesSchema(const Instruction *L, + const Instruction *R) const { + ImmutableCallSite LCS(L); + ImmutableCallSite RCS(R); + + assert(LCS && RCS && "Must be calls or invokes!"); + assert(LCS.isCall() == RCS.isCall() && "Can't compare otherwise!"); + + if (int Res = + cmpNumbers(LCS.getNumOperandBundles(), RCS.getNumOperandBundles())) + return Res; + + for (unsigned i = 0, e = LCS.getNumOperandBundles(); i != e; ++i) { + auto OBL = LCS.getOperandBundleAt(i); + auto OBR = RCS.getOperandBundleAt(i); + + if (int Res = OBL.getTagName().compare(OBR.getTagName())) + return Res; + + if (int Res = cmpNumbers(OBL.Inputs.size(), OBR.Inputs.size())) + return Res; + } + + return 0; +} + /// Constants comparison: /// 1. Check whether type of L constant could be losslessly bitcasted to R /// type. @@ -941,6 +968,8 @@ int FunctionComparator::cmpOperations(const Instruction *L, if (int Res = cmpAttrs(CI->getAttributes(), cast(R)->getAttributes())) return Res; + if (int Res = cmpOperandBundlesSchema(CI, R)) + return Res; return cmpRangeMetadata( CI->getMetadata(LLVMContext::MD_range), cast(R)->getMetadata(LLVMContext::MD_range)); @@ -952,6 +981,8 @@ int FunctionComparator::cmpOperations(const Instruction *L, if (int Res = cmpAttrs(CI->getAttributes(), cast(R)->getAttributes())) return Res; + if (int Res = cmpOperandBundlesSchema(CI, R)) + return Res; return cmpRangeMetadata( CI->getMetadata(LLVMContext::MD_range), cast(R)->getMetadata(LLVMContext::MD_range)); diff --git a/test/Feature/OperandBundles/merge-func.ll b/test/Feature/OperandBundles/merge-func.ll new file mode 100644 index 00000000000..aad9262c901 --- /dev/null +++ b/test/Feature/OperandBundles/merge-func.ll @@ -0,0 +1,34 @@ +; RUN: opt -S -mergefunc < %s | FileCheck %s + +; Minor note: functions need to be at least three instructions long +; to be considered by -mergefunc. + +declare i32 @foo(...) + +define i32 @f() { +; CHECK-LABEL: @f( + entry: + %v0 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] + %v1 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] + %v2 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] + +; CHECK: %v0 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] +; CHECK: %v1 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] +; CHECK: %v2 = call i32 (...) @foo(i32 10) [ "foo"(i32 20) ] + + ret i32 %v2 +} + +define i32 @g() { +; CHECK-LABEL: @g( + entry: + %v0 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] + %v1 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] + %v2 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] + +; CHECK: %v0 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] +; CHECK: %v1 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] +; CHECK: %v2 = call i32 (...) @foo() [ "foo"(i32 10, i32 20) ] + + ret i32 %v2 +} -- 2.34.1