[llvm] r255527 - Teach haveSameSpecialState about operand bundles

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


Author: sanjoy
Date: Mon Dec 14 13:11:35 2015
New Revision: 255527

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

Added:
    llvm/trunk/test/Feature/OperandBundles/special-state.ll
Modified:
    llvm/trunk/include/llvm/IR/InstrTypes.h
    llvm/trunk/lib/IR/Instruction.cpp

Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=255527&r1=255526&r2=255527&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Mon Dec 14 13:11:35 2015
@@ -1447,6 +1447,18 @@ public:
     return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
   }
 
+  /// \brief Return true if \p Other has the same sequence of operand bundle
+  /// tags with the same number of operands on each one of them as this
+  /// OperandBundleUser.
+  bool hasIdenticalOperandBundleSchema(
+      const OperandBundleUser<InstrTy, OpIteratorTy> &Other) const {
+    if (getNumOperandBundles() != Other.getNumOperandBundles())
+      return false;
+
+    return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
+                      Other.bundle_op_info_begin());
+  };
+
 protected:
   /// \brief Is the function attribute S disallowed by some operand bundle on
   /// this operand bundle user?
@@ -1490,6 +1502,10 @@ protected:
     /// \brief The index in the Use& vector where operands for this operand
     /// bundle ends.
     uint32_t End;
+
+    bool operator==(const BundleOpInfo &Other) const {
+      return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
+    }
   };
 
   /// \brief Simple helper function to map a BundleOpInfo to an

Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=255527&r1=255526&r2=255527&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Mon Dec 14 13:11:35 2015
@@ -296,11 +296,12 @@ static bool haveSameSpecialState(const I
   if (const CallInst *CI = dyn_cast<CallInst>(I1))
     return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
            CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
-           CI->getAttributes() == cast<CallInst>(I2)->getAttributes();
+           CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
+           CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
   if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
     return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
-           CI->getAttributes() ==
-             cast<InvokeInst>(I2)->getAttributes();
+           CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
+           CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
   if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
     return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
   if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))

Added: llvm/trunk/test/Feature/OperandBundles/special-state.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/OperandBundles/special-state.ll?rev=255527&view=auto
==============================================================================
--- llvm/trunk/test/Feature/OperandBundles/special-state.ll (added)
+++ llvm/trunk/test/Feature/OperandBundles/special-state.ll Mon Dec 14 13:11:35 2015
@@ -0,0 +1,21 @@
+; RUN: opt -S -early-cse < %s | FileCheck %s
+
+; This test isn't directly related to EarlyCSE or varargs.  It is just
+; using these as a vehicle for testing the correctness of
+; haveSameSpecialState around operand bundles.
+
+declare i32 @foo(...)
+
+define i32 @f() {
+; CHECK-LABEL: @f(
+ entry:
+; CHECK: %v0 = call i32 (...) @foo(
+; CHECK: %v1 = call i32 (...) @foo(
+; CHECK: %v = add i32 %v0, %v1
+; CHECK: ret i32 %v
+
+  %v0 = call i32 (...) @foo(i32 10) readonly [ "foo"(i32 20) ]
+  %v1 = call i32 (...) @foo() readonly [ "foo"(i32 10, i32 20) ]
+  %v = add i32 %v0, %v1
+  ret i32 %v
+}




More information about the llvm-commits mailing list