[llvm] 908215b - Use AssumeInst in a few more places [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 6 13:19:04 PDT 2021


Author: Philip Reames
Date: 2021-04-06T13:18:53-07:00
New Revision: 908215b34636f579533ecd6671bb6213b8327dbc

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

LOG: Use AssumeInst in a few more places [nfc]

Follow up to a6d2a8d6f5.  These were found by simply grepping for "::assume", and are the subset of that result which looked cleaner to me using the isa/dyn_cast patterns.

Added: 
    

Modified: 
    llvm/lib/Analysis/AssumptionCache.cpp
    llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/lib/Analysis/TypeMetadataUtils.cpp
    llvm/lib/CodeGen/CodeGenPrepare.cpp
    llvm/lib/IR/User.cpp
    llvm/lib/IR/Value.cpp
    llvm/lib/Transforms/IPO/LowerTypeTests.cpp
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    llvm/lib/Transforms/Scalar/EarlyCSE.cpp
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index 753ea5fd8338..0d95b33601f9 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -202,9 +202,9 @@ void AssumptionCache::scanFunction() {
   // Go through all instructions in all blocks, add all calls to @llvm.assume
   // to this cache.
   for (BasicBlock &B : F)
-    for (Instruction &II : B)
-      if (match(&II, m_Intrinsic<Intrinsic::assume>()))
-        AssumeHandles.push_back({&II, ExprResultIdx});
+    for (Instruction &I : B)
+      if (isa<AssumeInst>(&I))
+        AssumeHandles.push_back({&I, ExprResultIdx});
 
   // Mark the scan as complete.
   Scanned = true;

diff  --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index e596327cba3b..b449b839782e 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -176,11 +176,7 @@ static void addIntrinsicToSummary(
     // Intrinsics that are assumed are relevant only to the devirtualization
     // pass, not the type test lowering pass.
     bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
-      auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
-      if (!AssumeCI)
-        return true;
-      Function *F = AssumeCI->getCalledFunction();
-      return !F || F->getIntrinsicID() != Intrinsic::assume;
+      return !isa<AssumeInst>(CIU.getUser());
     });
     if (HasNonAssumeUses)
       TypeTests.insert(Guid);

diff  --git a/llvm/lib/Analysis/TypeMetadataUtils.cpp b/llvm/lib/Analysis/TypeMetadataUtils.cpp
index 8735d56f907a..f015ba9a09ca 100644
--- a/llvm/lib/Analysis/TypeMetadataUtils.cpp
+++ b/llvm/lib/Analysis/TypeMetadataUtils.cpp
@@ -15,6 +15,7 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 
@@ -80,13 +81,9 @@ void llvm::findDevirtualizableCallsForTypeTest(
   const Module *M = CI->getParent()->getParent()->getParent();
 
   // Find llvm.assume intrinsics for this llvm.type.test call.
-  for (const Use &CIU : CI->uses()) {
-    if (auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser())) {
-      Function *F = AssumeCI->getCalledFunction();
-      if (F && F->getIntrinsicID() == Intrinsic::assume)
-        Assumes.push_back(AssumeCI);
-    }
-  }
+  for (const Use &CIU : CI->uses())
+    if (auto *Assume = dyn_cast<AssumeInst>(CIU.getUser()))
+      Assumes.push_back(Assume);
 
   // If we found any, search for virtual calls based on %p and add them to
   // DevirtCalls.

diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 7e05b307e170..d4702820aa3b 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -626,12 +626,10 @@ bool CodeGenPrepare::eliminateAssumptions(Function &F) {
     CurInstIterator = BB.begin();
     while (CurInstIterator != BB.end()) {
       Instruction *I = &*(CurInstIterator++);
-      if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
-        if (II->getIntrinsicID() != Intrinsic::assume)
-          continue;
+      if (auto *Assume = dyn_cast<AssumeInst>(I)) {
         MadeChange = true;
-        Value *Operand = II->getOperand(0);
-        II->eraseFromParent();
+        Value *Operand = Assume->getOperand(0);
+        Assume->eraseFromParent();
 
         resetIteratorIfInvalidatedWhileCalling(&BB, [&]() {
           RecursivelyDeleteTriviallyDeadInstructions(Operand, TLInfo, nullptr);

diff  --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index f4143163ab13..8837151f2e18 100644
--- a/llvm/lib/IR/User.cpp
+++ b/llvm/lib/IR/User.cpp
@@ -107,9 +107,7 @@ MutableArrayRef<uint8_t> User::getDescriptor() {
 }
 
 bool User::isDroppable() const {
-  if (const auto *Intr = dyn_cast<IntrinsicInst>(this))
-    return Intr->getIntrinsicID() == Intrinsic::assume;
-  return false;
+  return isa<AssumeInst>(this);
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index d54a95ce6ac8..544f4d6450e0 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -205,8 +205,7 @@ void Value::dropDroppableUsesIn(User &Usr) {
 
 void Value::dropDroppableUse(Use &U) {
   U.removeFromList();
-  if (auto *Assume = dyn_cast<IntrinsicInst>(U.getUser())) {
-    assert(Assume->getIntrinsicID() == Intrinsic::assume);
+  if (auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
     unsigned OpNo = U.getOperandNo();
     if (OpNo == 0)
       U.set(ConstantInt::getTrue(Assume->getContext()));

diff  --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 9204bec38239..8e72643d9a11 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1791,9 +1791,8 @@ bool LowerTypeTestsModule::lower() {
       auto *CI = cast<CallInst>((*UI++).getUser());
       // Find and erase llvm.assume intrinsics for this llvm.type.test call.
       for (auto CIU = CI->use_begin(), CIUE = CI->use_end(); CIU != CIUE;)
-        if (auto *II = dyn_cast<IntrinsicInst>((*CIU++).getUser()))
-          if (II->getIntrinsicID() == Intrinsic::assume)
-            II->eraseFromParent();
+        if (auto *Assume = dyn_cast<AssumeInst>((*CIU++).getUser()))
+          Assume->eraseFromParent();
       CI->eraseFromParent();
     }
 
@@ -2062,9 +2061,8 @@ bool LowerTypeTestsModule::lower() {
       // with the DropTypeTests flag set.
       bool OnlyAssumeUses = !CI->use_empty();
       for (const Use &CIU : CI->uses()) {
-        if (auto *II = dyn_cast<IntrinsicInst>(CIU.getUser()))
-          if (II->getIntrinsicID() == Intrinsic::assume)
-            continue;
+        if (isa<AssumeInst>(CIU.getUser()))
+          continue;
         OnlyAssumeUses = false;
         break;
       }

diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index cb3c0bba7759..050f871d4c45 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3982,8 +3982,8 @@ static bool combineInstructionsOverFunction(
       F.getContext(), TargetFolder(DL),
       IRBuilderCallbackInserter([&Worklist, &AC](Instruction *I) {
         Worklist.add(I);
-        if (match(I, m_Intrinsic<Intrinsic::assume>()))
-          AC.registerAssumption(cast<AssumeInst>(I));
+        if (auto *Assume = dyn_cast<AssumeInst>(I))
+          AC.registerAssumption(Assume);
       }));
 
   // Lower dbg.declare intrinsics otherwise their value may be clobbered

diff  --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index c152ce06a3a4..51ed5ae3a7d4 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -1219,9 +1219,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
     // they're marked as such to ensure preservation of control dependencies),
     // and this pass will not bother with its removal. However, we should mark
     // its condition as true for all dominated blocks.
-    if (match(&Inst, m_Intrinsic<Intrinsic::assume>())) {
-      auto *CondI =
-          dyn_cast<Instruction>(cast<CallInst>(Inst).getArgOperand(0));
+    if (auto *Assume = dyn_cast<AssumeInst>(&Inst)) {
+      auto *CondI = dyn_cast<Instruction>(Assume->getArgOperand(0));
       if (CondI && SimpleValue::canHandle(CondI)) {
         LLVM_DEBUG(dbgs() << "EarlyCSE considering assumption: " << Inst
                           << '\n');

diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 7eb4f4f07b93..11ca7d09e0cb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2529,8 +2529,9 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, DomTreeUpdater *DTU,
         EdgeBB->getInstList().insert(InsertPt, N);
 
         // Register the new instruction with the assumption cache if necessary.
-        if (AC && match(N, m_Intrinsic<Intrinsic::assume>()))
-          AC->registerAssumption(cast<AssumeInst>(N));
+        if (auto *Assume = dyn_cast<AssumeInst>(N))
+          if (AC)
+            AC->registerAssumption(Assume);
       }
     }
 


        


More information about the llvm-commits mailing list