[llvm-branch-commits] [llvm] c83cff4 - [IR] Add NoAliasScopeDeclInst (NFC)

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 23 13:45:24 PST 2021


Author: Nikita Popov
Date: 2021-01-23T22:40:32+01:00
New Revision: c83cff45c7a58010e65270d3f5bfb8c9a72ad832

URL: https://github.com/llvm/llvm-project/commit/c83cff45c7a58010e65270d3f5bfb8c9a72ad832
DIFF: https://github.com/llvm/llvm-project/commit/c83cff45c7a58010e65270d3f5bfb8c9a72ad832.diff

LOG: [IR] Add NoAliasScopeDeclInst (NFC)

Add an intrinsic type class to represent the
llvm.experimental.noalias.scope.decl intrinsic, to make code
working with it a bit nicer by hiding the metadata extraction
from view.

Added: 
    

Modified: 
    llvm/include/llvm/IR/IntrinsicInst.h
    llvm/lib/Transforms/Utils/InlineFunction.cpp
    llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index 52504582dd1d..12c464f8b8ba 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -989,6 +989,24 @@ class PseudoProbeInst : public IntrinsicInst {
     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
   }
 };
+
+class NoAliasScopeDeclInst : public IntrinsicInst {
+public:
+  static bool classof(const IntrinsicInst *I) {
+    return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
+  }
+
+  static bool classof(const Value *V) {
+    return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
+  }
+
+  MDNode *getScopeList() const {
+    auto *MV =
+        cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
+    return cast<MDNode>(MV->getMetadata());
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_INTRINSICINST_H

diff  --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index abdd2b2361b7..2f8f3666d396 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -859,13 +859,8 @@ ScopedAliasMetadataDeepCloner::ScopedAliasMetadataDeepCloner(
         MD.insert(M);
 
       // We also need to clone the metadata in noalias intrinsics.
-      if (const auto *II = dyn_cast<IntrinsicInst>(&I))
-        if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl)
-          if (const auto *M = dyn_cast<MDNode>(
-                  cast<MetadataAsValue>(
-                      II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg))
-                      ->getMetadata()))
-            MD.insert(M);
+      if (const auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
+        MD.insert(Decl->getScopeList());
     }
   }
   addRecursiveMetadataUses();
@@ -932,14 +927,11 @@ void ScopedAliasMetadataDeepCloner::remap(ValueToValueMapTy &VMap) {
     if (MDNode *M = I->getMetadata(LLVMContext::MD_noalias))
       I->setMetadata(LLVMContext::MD_noalias, MDMap[M]);
 
-    if (auto *II = dyn_cast<IntrinsicInst>(I))
-      if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl) {
-        auto *MV = cast<MetadataAsValue>(
-            II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
-        auto *NewMV = MetadataAsValue::get(
-            II->getContext(), MDMap[cast<MDNode>(MV->getMetadata())]);
-        II->setOperand(Intrinsic::NoAliasScopeDeclScopeArg, NewMV);
-      }
+    if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(I)) {
+      auto *NewMV =
+          MetadataAsValue::get(Decl->getContext(), MDMap[Decl->getScopeList()]);
+      Decl->setOperand(Intrinsic::NoAliasScopeDeclScopeArg, NewMV);
+    }
   }
 }
 

diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 2b873954f88b..2ab0848193f6 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -947,9 +947,8 @@ bool LoopVectorizationLegality::blockCanBePredicated(
     // Do not let llvm.experimental.noalias.scope.decl block the vectorization.
     // TODO: there might be cases that it should block the vectorization. Let's
     // ignore those for now.
-    if (match(&I, m_Intrinsic<Intrinsic::experimental_noalias_scope_decl>())) {
+    if (isa<NoAliasScopeDeclInst>(&I))
       continue;
-    }
 
     // We might be able to hoist the load.
     if (I.mayReadFromMemory()) {

diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 9e157f3061b6..9373d40458f4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2882,10 +2882,9 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr, VPUser &User,
 
   // llvm.experimental.noalias.scope.decl intrinsics must only be duplicated for
   // the first lane and part.
-  if (auto *II = dyn_cast<IntrinsicInst>(Instr))
+  if (isa<NoAliasScopeDeclInst>(Instr))
     if (Instance.Lane != 0 || Instance.Part != 0)
-      if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl)
-        return;
+      return;
 
   setDebugLocFromInst(Builder, Instr);
 


        


More information about the llvm-branch-commits mailing list