Skip to content

Commit 892dfd7

Browse files
committed
Merging r370355:
------------------------------------------------------------------------ r370355 | joerg | 2019-08-29 15:22:30 +0200 (Thu, 29 Aug 2019) | 5 lines 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: 370447
1 parent 25f22e7 commit 892dfd7

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"
@@ -263,12 +264,14 @@ Value *SimplifyInstruction(Instruction *I, const SimplifyQuery &Q,
263264
/// This first performs a normal RAUW of I with SimpleV. It then recursively
264265
/// attempts to simplify those users updated by the operation. The 'I'
265266
/// instruction must not be equal to the simplified value 'SimpleV'.
267+
/// If UnsimplifiedUsers is provided, instructions that could not be simplified
268+
/// are added to it.
266269
///
267270
/// The function returns true if any simplifications were performed.
268-
bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
269-
const TargetLibraryInfo *TLI = nullptr,
270-
const DominatorTree *DT = nullptr,
271-
AssumptionCache *AC = nullptr);
271+
bool replaceAndRecursivelySimplify(
272+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI = nullptr,
273+
const DominatorTree *DT = nullptr, AssumptionCache *AC = nullptr,
274+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers = nullptr);
272275

273276
/// Recursively attempt to simplify an instruction.
274277
///

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5221,14 +5221,16 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ,
52215221
/// If we have a pre-simplified value in 'SimpleV', that is forcibly used to
52225222
/// replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
52235223
/// instructions to process and attempt to simplify it using
5224-
/// InstructionSimplify.
5224+
/// InstructionSimplify. Recursively visited users which could not be
5225+
/// simplified themselves are to the optional UnsimplifiedUsers set for
5226+
/// further processing by the caller.
52255227
///
52265228
/// This routine returns 'true' only when *it* simplifies something. The passed
52275229
/// in simplified value does not count toward this.
5228-
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
5229-
const TargetLibraryInfo *TLI,
5230-
const DominatorTree *DT,
5231-
AssumptionCache *AC) {
5230+
static bool replaceAndRecursivelySimplifyImpl(
5231+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5232+
const DominatorTree *DT, AssumptionCache *AC,
5233+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers = nullptr) {
52325234
bool Simplified = false;
52335235
SmallSetVector<Instruction *, 8> Worklist;
52345236
const DataLayout &DL = I->getModule()->getDataLayout();
@@ -5258,8 +5260,11 @@ static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
52585260

52595261
// See if this instruction simplifies.
52605262
SimpleV = SimplifyInstruction(I, {DL, TLI, DT, AC});
5261-
if (!SimpleV)
5263+
if (!SimpleV) {
5264+
if (UnsimplifiedUsers)
5265+
UnsimplifiedUsers->insert(I);
52625266
continue;
5267+
}
52635268

52645269
Simplified = true;
52655270

@@ -5285,16 +5290,17 @@ bool llvm::recursivelySimplifyInstruction(Instruction *I,
52855290
const TargetLibraryInfo *TLI,
52865291
const DominatorTree *DT,
52875292
AssumptionCache *AC) {
5288-
return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC);
5293+
return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC, nullptr);
52895294
}
52905295

5291-
bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
5292-
const TargetLibraryInfo *TLI,
5293-
const DominatorTree *DT,
5294-
AssumptionCache *AC) {
5296+
bool llvm::replaceAndRecursivelySimplify(
5297+
Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5298+
const DominatorTree *DT, AssumptionCache *AC,
5299+
SmallSetVector<Instruction *, 8> *UnsimplifiedUsers) {
52955300
assert(I != SimpleV && "replaceAndRecursivelySimplify(X,X) is not valid!");
52965301
assert(SimpleV && "Must provide a simplified value.");
5297-
return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC);
5302+
return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC,
5303+
UnsimplifiedUsers);
52985304
}
52995305

53005306
namespace llvm {

0 commit comments

Comments
 (0)