@@ -5309,14 +5309,16 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ,
5309
5309
// / If we have a pre-simplified value in 'SimpleV', that is forcibly used to
5310
5310
// / replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
5311
5311
// / 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.
5313
5315
// /
5314
5316
// / This routine returns 'true' only when *it* simplifies something. The passed
5315
5317
// / 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 ) {
5320
5322
bool Simplified = false ;
5321
5323
SmallSetVector<Instruction *, 8 > Worklist;
5322
5324
const DataLayout &DL = I->getModule ()->getDataLayout ();
@@ -5346,8 +5348,11 @@ static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
5346
5348
5347
5349
// See if this instruction simplifies.
5348
5350
SimpleV = SimplifyInstruction (I, {DL, TLI, DT, AC});
5349
- if (!SimpleV)
5351
+ if (!SimpleV) {
5352
+ if (UnsimplifiedUsers)
5353
+ UnsimplifiedUsers->insert (I);
5350
5354
continue ;
5355
+ }
5351
5356
5352
5357
Simplified = true ;
5353
5358
@@ -5373,16 +5378,17 @@ bool llvm::recursivelySimplifyInstruction(Instruction *I,
5373
5378
const TargetLibraryInfo *TLI,
5374
5379
const DominatorTree *DT,
5375
5380
AssumptionCache *AC) {
5376
- return replaceAndRecursivelySimplifyImpl (I, nullptr , TLI, DT, AC);
5381
+ return replaceAndRecursivelySimplifyImpl (I, nullptr , TLI, DT, AC, nullptr );
5377
5382
}
5378
5383
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 ) {
5383
5388
assert (I != SimpleV && " replaceAndRecursivelySimplify(X,X) is not valid!" );
5384
5389
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);
5386
5392
}
5387
5393
5388
5394
namespace llvm {
0 commit comments