Skip to content

Commit 799c966

Browse files
committed
Allow replaceAndRecursivelySimplify to list unsimplified visitees.
This is part of D65280 and split it to avoid ABI changes on the 9.0 release branch. llvm-svn: 370355
1 parent b23857c commit 799c966

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

llvm/include/llvm/Analysis/InstructionSimplify.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
3232
#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
3333

34+
#include "llvm/ADT/SetVector.h"
3435
#include "llvm/IR/Instruction.h"
3536
#include "llvm/IR/Operator.h"
3637
#include "llvm/IR/User.h"
@@ -261,12 +262,14 @@ Value *SimplifyInstruction(Instruction *I, const SimplifyQuery &Q,
261262
/// This first performs a normal RAUW of I with SimpleV. It then recursively
262263
/// attempts to simplify those users updated by the operation. The 'I'
263264
/// instruction must not be equal to the simplified value 'SimpleV'.
265+
/// If UnsimplifiedUsers is provided, instructions that could not be simplified
266+
/// are added to it.
264267
///
265268
/// The function returns true if any simplifications were performed.
266-
bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
267-
const TargetLibraryInfo *TLI = nullptr,
268-
const DominatorTree *DT = nullptr,
269-
AssumptionCache *AC = nullptr);
269+
bool replaceAndRecursivelySimplify(
270+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI = nullptr,
271+
const DominatorTree *DT = nullptr, AssumptionCache *AC = nullptr,
272+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers = nullptr);
270273

271274
/// Recursively attempt to simplify an instruction.
272275
///

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5309,14 +5309,16 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ,
53095309
/// If we have a pre-simplified value in 'SimpleV', that is forcibly used to
53105310
/// replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
53115311
/// instructions to process and attempt to simplify it using
5312-
/// InstructionSimplify.
5312+
/// InstructionSimplify. Recursively visited users which could not be
5313+
/// simplified themselves are to the optional UnsimplifiedUsers set for
5314+
/// further processing by the caller.
53135315
///
53145316
/// This routine returns 'true' only when *it* simplifies something. The passed
53155317
/// in simplified value does not count toward this.
5316-
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
5317-
const TargetLibraryInfo *TLI,
5318-
const DominatorTree *DT,
5319-
AssumptionCache *AC) {
5318+
static bool replaceAndRecursivelySimplifyImpl(
5319+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5320+
const DominatorTree *DT, AssumptionCache *AC,
5321+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers = nullptr) {
53205322
bool Simplified = false;
53215323
SmallSetVector<Instruction *, 8> Worklist;
53225324
const DataLayout &DL = I->getModule()->getDataLayout();
@@ -5346,8 +5348,11 @@ static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
53465348

53475349
// See if this instruction simplifies.
53485350
SimpleV = SimplifyInstruction(I, {DL, TLI, DT, AC});
5349-
if (!SimpleV)
5351+
if (!SimpleV) {
5352+
if (UnsimplifiedUsers)
5353+
UnsimplifiedUsers->insert(I);
53505354
continue;
5355+
}
53515356

53525357
Simplified = true;
53535358

@@ -5373,16 +5378,17 @@ bool llvm::recursivelySimplifyInstruction(Instruction *I,
53735378
const TargetLibraryInfo *TLI,
53745379
const DominatorTree *DT,
53755380
AssumptionCache *AC) {
5376-
return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC);
5381+
return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC, nullptr);
53775382
}
53785383

5379-
bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
5380-
const TargetLibraryInfo *TLI,
5381-
const DominatorTree *DT,
5382-
AssumptionCache *AC) {
5384+
bool llvm::replaceAndRecursivelySimplify(
5385+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5386+
const DominatorTree *DT, AssumptionCache *AC,
5387+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers) {
53835388
assert(I != SimpleV && "replaceAndRecursivelySimplify(X,X) is not valid!");
53845389
assert(SimpleV && "Must provide a simplified value.");
5385-
return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC);
5390+
return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC,
5391+
UnsimplifiedUsers);
53865392
}
53875393

53885394
namespace llvm {

0 commit comments

Comments
 (0)