@@ -11,13 +11,15 @@ struct PeepholeContext : InstPassBase
11
11
{
12
12
PeepholeContext (IRModule* inModule)
13
13
: InstPassBase(inModule)
14
- {}
14
+ {
15
+ }
15
16
16
17
bool changed = false ;
17
18
FloatingPointMode floatingPointMode = FloatingPointMode::Precise;
18
19
bool removeOldInst = true ;
19
20
bool isInGeneric = false ;
20
21
bool isPrelinking = false ;
22
+ bool useFastAnalysis = false ;
21
23
22
24
TargetProgram* targetProgram;
23
25
@@ -350,7 +352,7 @@ struct PeepholeContext : InstPassBase
350
352
}
351
353
else
352
354
{
353
- // changed |= tryFoldElementExtractFromUpdateInst(inst);
355
+ changed |= tryFoldElementExtractFromUpdateInst (inst);
354
356
}
355
357
break ;
356
358
case kIROp_GetElement :
@@ -415,7 +417,7 @@ struct PeepholeContext : InstPassBase
415
417
}
416
418
else
417
419
{
418
- // changed |= tryFoldElementExtractFromUpdateInst(inst);
420
+ changed |= tryFoldElementExtractFromUpdateInst (inst);
419
421
}
420
422
break ;
421
423
case kIROp_UpdateElement :
@@ -846,7 +848,7 @@ struct PeepholeContext : InstPassBase
846
848
case kIROp_Div :
847
849
case kIROp_And :
848
850
case kIROp_Or :
849
- // changed |= tryOptimizeArithmeticInst(inst);
851
+ changed |= tryOptimizeArithmeticInst (inst);
850
852
break ;
851
853
case kIROp_Param :
852
854
{
@@ -895,8 +897,7 @@ struct PeepholeContext : InstPassBase
895
897
// Never remove param inst.
896
898
changed = true ;
897
899
}
898
- #if 0
899
- else
900
+ else if (!useFastAnalysis)
900
901
{
901
902
// If argValue is defined locally,
902
903
// we can replace only if argVal dominates inst.
@@ -913,7 +914,6 @@ struct PeepholeContext : InstPassBase
913
914
changed = true ;
914
915
}
915
916
}
916
- #endif
917
917
}
918
918
}
919
919
}
@@ -1120,7 +1120,8 @@ struct PeepholeContext : InstPassBase
1120
1120
1121
1121
bool processFunc (IRInst* func)
1122
1122
{
1123
- func->getModule ()->invalidateAllAnalysis ();
1123
+ if (!useFastAnalysis)
1124
+ func->getModule ()->invalidateAllAnalysis ();
1124
1125
1125
1126
bool lastIsInGeneric = isInGeneric;
1126
1127
if (!isInGeneric)
@@ -1153,21 +1154,27 @@ bool peepholeOptimize(TargetProgram* target, IRModule* module, PeepholeOptimizat
1153
1154
PeepholeContext context = PeepholeContext (module);
1154
1155
context.targetProgram = target;
1155
1156
context.isPrelinking = options.isPrelinking ;
1157
+ context.useFastAnalysis = target
1158
+ ? target->getOptionSet ().getBoolOption (CompilerOptionName::MinimumSlangOptimization)
1159
+ : true ;
1156
1160
return context.processModule ();
1157
1161
}
1158
1162
1159
1163
bool peepholeOptimize (TargetProgram* target, IRInst* func)
1160
1164
{
1161
1165
PeepholeContext context = PeepholeContext (func->getModule ());
1162
1166
context.targetProgram = target;
1167
+ context.useFastAnalysis = target
1168
+ ? target->getOptionSet ().getBoolOption (CompilerOptionName::MinimumSlangOptimization)
1169
+ : true ;
1163
1170
return context.processFunc (func);
1164
1171
}
1165
1172
1166
1173
bool peepholeOptimizeGlobalScope (TargetProgram* target, IRModule* module)
1167
1174
{
1168
1175
PeepholeContext context = PeepholeContext (module);
1169
1176
context.targetProgram = target;
1170
-
1177
+ context. useFastAnalysis = true ;
1171
1178
bool result = false ;
1172
1179
for (;;)
1173
1180
{
@@ -1189,6 +1196,7 @@ bool tryReplaceInstUsesWithSimplifiedValue(TargetProgram* target, IRModule* modu
1189
1196
PeepholeContext context = PeepholeContext (inst->getModule ());
1190
1197
context.targetProgram = target;
1191
1198
context.removeOldInst = false ;
1199
+ context.useFastAnalysis = true ;
1192
1200
context.processInst (inst);
1193
1201
return context.changed ;
1194
1202
}
0 commit comments