[llvm] r255528 - Teach MergeFunctions about operand bundles

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 11:11:40 PST 2015


Author: sanjoy
Date: Mon Dec 14 13:11:40 2015
New Revision: 255528

URL: http://llvm.org/viewvc/llvm-project?rev=255528&view=rev
Log:
Teach MergeFunctions about operand bundles

Added:
    llvm/trunk/test/Feature/OperandBundles/merge-func.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=255528&r1=255527&r2=255528&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Mon Dec 14 13:11:40 2015
@@ -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
   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(co
     if (int Res =
             cmpAttrs(CI->getAttributes(), cast<CallInst>(R)->getAttributes()))
       return Res;
+    if (int Res = cmpOperandBundlesSchema(CI, R))
+      return Res;
     return cmpRangeMetadata(
         CI->getMetadata(LLVMContext::MD_range),
         cast<CallInst>(R)->getMetadata(LLVMContext::MD_range));
@@ -952,6 +981,8 @@ int FunctionComparator::cmpOperations(co
     if (int Res =
             cmpAttrs(CI->getAttributes(), cast<InvokeInst>(R)->getAttributes()))
       return Res;
+    if (int Res = cmpOperandBundlesSchema(CI, R))
+      return Res;
     return cmpRangeMetadata(
         CI->getMetadata(LLVMContext::MD_range),
         cast<InvokeInst>(R)->getMetadata(LLVMContext::MD_range));

Added: llvm/trunk/test/Feature/OperandBundles/merge-func.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/OperandBundles/merge-func.ll?rev=255528&view=auto
==============================================================================
--- llvm/trunk/test/Feature/OperandBundles/merge-func.ll (added)
+++ llvm/trunk/test/Feature/OperandBundles/merge-func.ll Mon Dec 14 13:11:40 2015
@@ -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
+}




More information about the llvm-commits mailing list