@@ -245,6 +245,8 @@ class AMDGPUCodeGenPrepareImpl
245245 Value *emitSqrtIEEE2ULP (IRBuilder<> &Builder, Value *Src,
246246 FastMathFlags FMF) const ;
247247
248+ bool tryNarrowMathIfNoOverflow (Instruction *I);
249+
248250public:
249251 bool visitFDiv (BinaryOperator &I);
250252
@@ -284,6 +286,9 @@ bool AMDGPUCodeGenPrepareImpl::run() {
284286 BreakPhiNodesCache.clear ();
285287 bool MadeChange = false ;
286288
289+ // Need to use make_early_inc_range because integer division expansion is
290+ // handled by Transform/Utils, and it can delete instructions such as the
291+ // terminator of the BB.
287292 for (BasicBlock &BB : reverse (F)) {
288293 for (Instruction &I : make_early_inc_range (reverse (BB))) {
289294 if (!isInstructionTriviallyDead (&I, TLI))
@@ -1295,11 +1300,7 @@ it will create `s_and_b32 s0, s0, 0xff`.
12951300We accept this change since the non-byte load assumes the upper bits
12961301within the byte are all 0.
12971302*/
1298- static bool tryNarrowMathIfNoOverflow (Instruction *I,
1299- const SITargetLowering *TLI,
1300- const TargetTransformInfo &TTI,
1301- const DataLayout &DL,
1302- SmallVector<WeakVH> &DeadVals) {
1303+ bool AMDGPUCodeGenPrepareImpl::tryNarrowMathIfNoOverflow (Instruction *I) {
13031304 unsigned Opc = I->getOpcode ();
13041305 Type *OldType = I->getType ();
13051306
@@ -1324,6 +1325,7 @@ static bool tryNarrowMathIfNoOverflow(Instruction *I,
13241325 NewType = I->getType ()->getWithNewBitWidth (NewBit);
13251326
13261327 // Old cost
1328+ const TargetTransformInfo &TTI = TM.getTargetTransformInfo (F);
13271329 InstructionCost OldCost =
13281330 TTI.getArithmeticInstrCost (Opc, OldType, TTI::TCK_RecipThroughput);
13291331 // New cost of new op
@@ -1364,8 +1366,7 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) {
13641366
13651367 if (UseMul24Intrin && replaceMulWithMul24 (I))
13661368 return true ;
1367- if (tryNarrowMathIfNoOverflow (&I, ST.getTargetLowering (),
1368- TM.getTargetTransformInfo (F), DL, DeadVals))
1369+ if (tryNarrowMathIfNoOverflow (&I))
13691370 return true ;
13701371
13711372 bool Changed = false ;
0 commit comments