@@ -4258,72 +4258,78 @@ bool IGCConstProp::runOnFunction(Function& F)
4258
4258
module = F.getParent ();
4259
4259
// Initialize the worklist to all of the instructions ready to process...
4260
4260
llvm::SetVector<Instruction*> WorkList;
4261
- for (inst_iterator i = inst_begin (F), e = inst_end (F); i != e; ++i)
4262
- {
4263
- WorkList.insert (&*i);
4264
- }
4265
4261
bool Changed = false ;
4266
- m_TD = &F.getParent ()->getDataLayout ();
4267
- m_TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI ();
4268
- while (!WorkList.empty ())
4262
+ bool NotClosed;
4263
+ do // Fold constants until closure
4269
4264
{
4270
- Instruction* I = WorkList. pop_back_val (); // Get an element from the worklist...
4271
- if (I-> use_empty ()) // Don't muck with dead instructions...
4265
+ NotClosed = false ;
4266
+ for (inst_iterator i = inst_begin (F), e = inst_end (F); i != e; ++i)
4272
4267
{
4273
- continue ;
4268
+ WorkList. insert (&*i) ;
4274
4269
}
4275
- Constant* C = nullptr ;
4276
- C = ConstantFoldInstruction (I, *m_TD, m_TLI);
4277
-
4278
- if (!C && isa<CallInst>(I))
4270
+ m_TD = &F.getParent ()->getDataLayout ();
4271
+ m_TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI ();
4272
+ while (!WorkList.empty ())
4279
4273
{
4280
- C = ConstantFoldCallInstruction (cast<CallInst>(I));
4281
- }
4274
+ Instruction* I = WorkList.pop_back_val (); // Get an element from the worklist...
4275
+ if (I->use_empty ()) // Don't muck with dead instructions...
4276
+ {
4277
+ continue ;
4278
+ }
4279
+ Constant* C = nullptr ;
4280
+ C = ConstantFoldInstruction (I, *m_TD, m_TLI);
4282
4281
4283
- // replace shader-constant load with the known value
4284
- if (!C && isa<LoadInst>(I))
4285
- {
4286
- C = replaceShaderConstant (cast<LoadInst>(I));
4287
- }
4288
- if (!C && isa<CmpInst>(I))
4289
- {
4290
- C = ConstantFoldCmpInst (cast<CmpInst>(I));
4291
- }
4292
- if (!C && isa<ExtractElementInst>(I))
4293
- {
4294
- C = ConstantFoldExtractElement (cast<ExtractElementInst>(I));
4295
- }
4296
- if (C)
4297
- {
4298
- // Add all of the users of this instruction to the worklist, they might
4299
- // be constant propagatable now...
4300
- for (Value::user_iterator UI = I->user_begin (), UE = I->user_end ();
4301
- UI != UE; ++UI)
4282
+ if (!C && isa<CallInst>(I))
4302
4283
{
4303
- WorkList. insert (cast<Instruction>(*UI ));
4284
+ C = ConstantFoldCallInstruction (cast<CallInst>(I ));
4304
4285
}
4305
4286
4306
- // Replace all of the uses of a variable with uses of the constant.
4307
- I->replaceAllUsesWith (C);
4287
+ // replace shader-constant load with the known value
4288
+ if (!C && isa<LoadInst>(I))
4289
+ {
4290
+ C = replaceShaderConstant (cast<LoadInst>(I));
4291
+ }
4292
+ if (!C && isa<CmpInst>(I))
4293
+ {
4294
+ C = ConstantFoldCmpInst (cast<CmpInst>(I));
4295
+ }
4296
+ if (!C && isa<ExtractElementInst>(I))
4297
+ {
4298
+ C = ConstantFoldExtractElement (cast<ExtractElementInst>(I));
4299
+ }
4308
4300
4309
- // Remove the dead instruction.
4310
- I->eraseFromParent ();
4301
+ if (C)
4302
+ {
4303
+ // Add all of the users of this instruction to the worklist, they might
4304
+ // be constant propagatable now...
4305
+ for (Value::user_iterator UI = I->user_begin (), UE = I->user_end ();
4306
+ UI != UE; ++UI)
4307
+ {
4308
+ WorkList.insert (cast<Instruction>(*UI));
4309
+ }
4311
4310
4312
- // We made a change to the function.. .
4313
- Changed = true ;
4311
+ // Replace all of the uses of a variable with uses of the constant .
4312
+ I-> replaceAllUsesWith (C) ;
4314
4313
4315
- // I is erased, continue to the next one.
4316
- continue ;
4317
- }
4314
+ // Remove the dead instruction.
4315
+ I->eraseFromParent ();
4318
4316
4319
- if (GetElementPtrInst * GEP = dyn_cast<GetElementPtrInst>(I))
4320
- {
4321
- if ((m_enableSimplifyGEP || overrideEnableSimplifyGEP) && simplifyGEP (GEP))
4317
+ // We made a change to the function...
4318
+ Changed = NotClosed = true ;
4319
+
4320
+ // I is erased, continue to the next one.
4321
+ continue ;
4322
+ }
4323
+
4324
+ if (GetElementPtrInst * GEP = dyn_cast<GetElementPtrInst>(I))
4322
4325
{
4323
- Changed = true ;
4326
+ if ((m_enableSimplifyGEP || overrideEnableSimplifyGEP) && simplifyGEP (GEP))
4327
+ {
4328
+ Changed = NotClosed = true ;
4329
+ }
4324
4330
}
4325
4331
}
4326
- }
4332
+ } while (NotClosed);
4327
4333
return Changed;
4328
4334
}
4329
4335
0 commit comments