Skip to content

Commit 908215b

Browse files
committed
Use AssumeInst in a few more places [nfc]
Follow up to a6d2a8d. 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.
1 parent 69190f9 commit 908215b

File tree

10 files changed

+24
-38
lines changed

10 files changed

+24
-38
lines changed

llvm/lib/Analysis/AssumptionCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ void AssumptionCache::scanFunction() {
202202
// Go through all instructions in all blocks, add all calls to @llvm.assume
203203
// to this cache.
204204
for (BasicBlock &B : F)
205-
for (Instruction &II : B)
206-
if (match(&II, m_Intrinsic<Intrinsic::assume>()))
207-
AssumeHandles.push_back({&II, ExprResultIdx});
205+
for (Instruction &I : B)
206+
if (isa<AssumeInst>(&I))
207+
AssumeHandles.push_back({&I, ExprResultIdx});
208208

209209
// Mark the scan as complete.
210210
Scanned = true;

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ static void addIntrinsicToSummary(
176176
// Intrinsics that are assumed are relevant only to the devirtualization
177177
// pass, not the type test lowering pass.
178178
bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
179-
auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
180-
if (!AssumeCI)
181-
return true;
182-
Function *F = AssumeCI->getCalledFunction();
183-
return !F || F->getIntrinsicID() != Intrinsic::assume;
179+
return !isa<AssumeInst>(CIU.getUser());
184180
});
185181
if (HasNonAssumeUses)
186182
TypeTests.insert(Guid);

llvm/lib/Analysis/TypeMetadataUtils.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/IR/Constants.h"
1616
#include "llvm/IR/Dominators.h"
1717
#include "llvm/IR/Instructions.h"
18+
#include "llvm/IR/IntrinsicInst.h"
1819
#include "llvm/IR/Intrinsics.h"
1920
#include "llvm/IR/Module.h"
2021

@@ -80,13 +81,9 @@ void llvm::findDevirtualizableCallsForTypeTest(
8081
const Module *M = CI->getParent()->getParent()->getParent();
8182

8283
// Find llvm.assume intrinsics for this llvm.type.test call.
83-
for (const Use &CIU : CI->uses()) {
84-
if (auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser())) {
85-
Function *F = AssumeCI->getCalledFunction();
86-
if (F && F->getIntrinsicID() == Intrinsic::assume)
87-
Assumes.push_back(AssumeCI);
88-
}
89-
}
84+
for (const Use &CIU : CI->uses())
85+
if (auto *Assume = dyn_cast<AssumeInst>(CIU.getUser()))
86+
Assumes.push_back(Assume);
9087

9188
// If we found any, search for virtual calls based on %p and add them to
9289
// DevirtCalls.

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,10 @@ bool CodeGenPrepare::eliminateAssumptions(Function &F) {
626626
CurInstIterator = BB.begin();
627627
while (CurInstIterator != BB.end()) {
628628
Instruction *I = &*(CurInstIterator++);
629-
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
630-
if (II->getIntrinsicID() != Intrinsic::assume)
631-
continue;
629+
if (auto *Assume = dyn_cast<AssumeInst>(I)) {
632630
MadeChange = true;
633-
Value *Operand = II->getOperand(0);
634-
II->eraseFromParent();
631+
Value *Operand = Assume->getOperand(0);
632+
Assume->eraseFromParent();
635633

636634
resetIteratorIfInvalidatedWhileCalling(&BB, [&]() {
637635
RecursivelyDeleteTriviallyDeadInstructions(Operand, TLInfo, nullptr);

llvm/lib/IR/User.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ MutableArrayRef<uint8_t> User::getDescriptor() {
107107
}
108108

109109
bool User::isDroppable() const {
110-
if (const auto *Intr = dyn_cast<IntrinsicInst>(this))
111-
return Intr->getIntrinsicID() == Intrinsic::assume;
112-
return false;
110+
return isa<AssumeInst>(this);
113111
}
114112

115113
//===----------------------------------------------------------------------===//

llvm/lib/IR/Value.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ void Value::dropDroppableUsesIn(User &Usr) {
205205

206206
void Value::dropDroppableUse(Use &U) {
207207
U.removeFromList();
208-
if (auto *Assume = dyn_cast<IntrinsicInst>(U.getUser())) {
209-
assert(Assume->getIntrinsicID() == Intrinsic::assume);
208+
if (auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
210209
unsigned OpNo = U.getOperandNo();
211210
if (OpNo == 0)
212211
U.set(ConstantInt::getTrue(Assume->getContext()));

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,8 @@ bool LowerTypeTestsModule::lower() {
17911791
auto *CI = cast<CallInst>((*UI++).getUser());
17921792
// Find and erase llvm.assume intrinsics for this llvm.type.test call.
17931793
for (auto CIU = CI->use_begin(), CIUE = CI->use_end(); CIU != CIUE;)
1794-
if (auto *II = dyn_cast<IntrinsicInst>((*CIU++).getUser()))
1795-
if (II->getIntrinsicID() == Intrinsic::assume)
1796-
II->eraseFromParent();
1794+
if (auto *Assume = dyn_cast<AssumeInst>((*CIU++).getUser()))
1795+
Assume->eraseFromParent();
17971796
CI->eraseFromParent();
17981797
}
17991798

@@ -2062,9 +2061,8 @@ bool LowerTypeTestsModule::lower() {
20622061
// with the DropTypeTests flag set.
20632062
bool OnlyAssumeUses = !CI->use_empty();
20642063
for (const Use &CIU : CI->uses()) {
2065-
if (auto *II = dyn_cast<IntrinsicInst>(CIU.getUser()))
2066-
if (II->getIntrinsicID() == Intrinsic::assume)
2067-
continue;
2064+
if (isa<AssumeInst>(CIU.getUser()))
2065+
continue;
20682066
OnlyAssumeUses = false;
20692067
break;
20702068
}

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,8 +3982,8 @@ static bool combineInstructionsOverFunction(
39823982
F.getContext(), TargetFolder(DL),
39833983
IRBuilderCallbackInserter([&Worklist, &AC](Instruction *I) {
39843984
Worklist.add(I);
3985-
if (match(I, m_Intrinsic<Intrinsic::assume>()))
3986-
AC.registerAssumption(cast<AssumeInst>(I));
3985+
if (auto *Assume = dyn_cast<AssumeInst>(I))
3986+
AC.registerAssumption(Assume);
39873987
}));
39883988

39893989
// Lower dbg.declare intrinsics otherwise their value may be clobbered

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
12191219
// they're marked as such to ensure preservation of control dependencies),
12201220
// and this pass will not bother with its removal. However, we should mark
12211221
// its condition as true for all dominated blocks.
1222-
if (match(&Inst, m_Intrinsic<Intrinsic::assume>())) {
1223-
auto *CondI =
1224-
dyn_cast<Instruction>(cast<CallInst>(Inst).getArgOperand(0));
1222+
if (auto *Assume = dyn_cast<AssumeInst>(&Inst)) {
1223+
auto *CondI = dyn_cast<Instruction>(Assume->getArgOperand(0));
12251224
if (CondI && SimpleValue::canHandle(CondI)) {
12261225
LLVM_DEBUG(dbgs() << "EarlyCSE considering assumption: " << Inst
12271226
<< '\n');

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,8 +2529,9 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, DomTreeUpdater *DTU,
25292529
EdgeBB->getInstList().insert(InsertPt, N);
25302530

25312531
// Register the new instruction with the assumption cache if necessary.
2532-
if (AC && match(N, m_Intrinsic<Intrinsic::assume>()))
2533-
AC->registerAssumption(cast<AssumeInst>(N));
2532+
if (auto *Assume = dyn_cast<AssumeInst>(N))
2533+
if (AC)
2534+
AC->registerAssumption(Assume);
25342535
}
25352536
}
25362537

0 commit comments

Comments
 (0)