]> granicus.if.org Git - llvm/commitdiff
[InstCombineCalls] Remove zero length atomic memcpy intrinsics
authorIgor Laevsky <igmyrj@gmail.com>
Wed, 8 Feb 2017 14:23:47 +0000 (14:23 +0000)
committerIgor Laevsky <igmyrj@gmail.com>
Wed, 8 Feb 2017 14:23:47 +0000 (14:23 +0000)
Differential Revision: https://reviews.llvm.org/D28909

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294452 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/IntrinsicInst.h
lib/Transforms/InstCombine/InstCombineCalls.cpp

index 7f4eb0e9df81b8836b339b1bd0b6b9f870c666a4..f69b5bfc0be2643a251232c882988fecaef78915 100644 (file)
@@ -191,6 +191,32 @@ namespace llvm {
     }
   };
 
+  /// This class represents atomic memcpy intrinsic
+  /// TODO: Integrate this class into MemIntrinsic hierarchy.
+  class ElementAtomicMemCpyInst : public IntrinsicInst {
+  public:
+    Value *getRawDest() const { return getArgOperand(0); }
+    Value *getRawSource() const { return getArgOperand(1); }
+
+    Value *getNumElements() const { return getArgOperand(2); }
+    void setNumElements(Value *V) { setArgOperand(2, V); }
+
+    uint64_t getSrcAlignment() const { return getParamAlignment(1); }
+    uint64_t getDstAlignment() const { return getParamAlignment(2); }
+
+    uint64_t getElementSizeInBytes() const {
+      Value *Arg = getArgOperand(3);
+      return cast<ConstantInt>(Arg)->getZExtValue();
+    }
+
+    static inline bool classof(const IntrinsicInst *I) {
+      return I->getIntrinsicID() == Intrinsic::memcpy_element_atomic;
+    }
+    static inline bool classof(const Value *V) {
+      return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
+    }
+  };
+
   /// This is the common base class for memset/memcpy/memmove.
   class MemIntrinsic : public IntrinsicInst {
   public:
index f088671c6d7e4ba9a4f9985198746eb31f2ddd63..13f2f9e9c721c7b16abcd5f11f7eb1778b5958e8 100644 (file)
@@ -1835,6 +1835,12 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
     if (Changed) return II;
   }
 
+  if (auto *AMI = dyn_cast<ElementAtomicMemCpyInst>(II)) {
+    if (Constant *C = dyn_cast<Constant>(AMI->getNumElements()))
+      if (C->isNullValue())
+        return eraseInstFromFunction(*AMI);
+  }
+
   if (Instruction *I = SimplifyNVVMIntrinsic(II, *this))
     return I;