@@ -5221,14 +5221,16 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ,
5221
5221
// / If we have a pre-simplified value in 'SimpleV', that is forcibly used to
5222
5222
// / replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
5223
5223
// / 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.
5225
5227
// /
5226
5228
// / This routine returns 'true' only when *it* simplifies something. The passed
5227
5229
// / 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 ) {
5232
5234
bool Simplified = false ;
5233
5235
SmallSetVector<Instruction *, 8 > Worklist;
5234
5236
const DataLayout &DL = I->getModule ()->getDataLayout ();
@@ -5258,8 +5260,11 @@ static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
5258
5260
5259
5261
// See if this instruction simplifies.
5260
5262
SimpleV = SimplifyInstruction (I, {DL, TLI, DT, AC});
5261
- if (!SimpleV)
5263
+ if (!SimpleV) {
5264
+ if (UnsimplifiedUsers)
5265
+ UnsimplifiedUsers->insert (I);
5262
5266
continue ;
5267
+ }
5263
5268
5264
5269
Simplified = true ;
5265
5270
@@ -5285,16 +5290,17 @@ bool llvm::recursivelySimplifyInstruction(Instruction *I,
5285
5290
const TargetLibraryInfo *TLI,
5286
5291
const DominatorTree *DT,
5287
5292
AssumptionCache *AC) {
5288
- return replaceAndRecursivelySimplifyImpl (I, nullptr , TLI, DT, AC);
5293
+ return replaceAndRecursivelySimplifyImpl (I, nullptr , TLI, DT, AC, nullptr );
5289
5294
}
5290
5295
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 ) {
5295
5300
assert (I != SimpleV && " replaceAndRecursivelySimplify(X,X) is not valid!" );
5296
5301
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);
5298
5304
}
5299
5305
5300
5306
namespace llvm {
0 commit comments