Skip to content

Commit d878724

Browse files
committed
fix issue related to Blocks
Change-Id: I4afe203a6cedb0134812143e7211ca9e80ce6687
1 parent 6ecfd1f commit d878724

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,6 @@ class CodeGenPrepare {
435435
bool optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, Type *AccessTy,
436436
unsigned AddrSpace);
437437
bool optimizeGatherScatterInst(Instruction *MemoryInst, Value *Ptr);
438-
bool optimizeUMulWithOverflow(Instruction *I);
439-
bool optimizeSMulWithOverflow(Instruction *I);
440438
bool optimizeMulWithOverflow(Instruction *I, bool IsSigned,
441439
ModifyDT &ModifiedDT);
442440
bool optimizeInlineAsmInst(CallInst *CS);
@@ -6462,19 +6460,21 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
64626460
// overflow.res:
64636461

64646462
// New BBs:
6465-
BasicBlock *OverflowoEntryBB =
6463+
std::string KeepBBName = I->getParent()->getName().str();
6464+
BasicBlock *OverflowEntryBB =
64666465
I->getParent()->splitBasicBlock(I, "overflow.entry", /*Before*/ true);
64676466
// Remove the 'br' instruction that is generated as a result of the split:
6468-
OverflowoEntryBB->getTerminator()->eraseFromParent();
6467+
OverflowEntryBB->getTerminator()->eraseFromParent();
64696468
BasicBlock *NoOverflowBB =
64706469
BasicBlock::Create(I->getContext(), "overflow.no", I->getFunction());
6471-
NoOverflowBB->moveAfter(OverflowoEntryBB);
6472-
I->getParent()->setName("overflow");
6473-
BasicBlock *OverflowBB = I->getParent();
6470+
NoOverflowBB->moveAfter(OverflowEntryBB);
6471+
BasicBlock *OverflowBB =
6472+
BasicBlock::Create(I->getContext(), "overflow", I->getFunction());
6473+
OverflowBB->moveAfter(NoOverflowBB);
64746474

64756475
// BB overflow.entry:
6476+
IRBuilder<> Builder(OverflowEntryBB);
64766477
// Get Lo and Hi of LHS & RHS:
6477-
IRBuilder<> Builder(OverflowoEntryBB);
64786478
Value *LoLHS = Builder.CreateTrunc(LHS, LegalTy, "lo.lhs");
64796479
Value *HiLHS = Builder.CreateLShr(LHS, VTHalfBitWidth, "lhs.lsr");
64806480
HiLHS = Builder.CreateTrunc(HiLHS, LegalTy, "hi.lhs");
@@ -6504,16 +6504,7 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
65046504

65056505
// BB overflow.no:
65066506
Builder.SetInsertPoint(NoOverflowBB);
6507-
Value *ExtLoLHS, *ExtLoRHS;
6508-
if (IsSigned) {
6509-
ExtLoLHS = Builder.CreateSExt(LoLHS, Ty, "lo.lhs.ext");
6510-
ExtLoRHS = Builder.CreateSExt(LoRHS, Ty, "lo.rhs.ext");
6511-
} else {
6512-
ExtLoLHS = Builder.CreateZExt(LoLHS, Ty, "lo.lhs.ext");
6513-
ExtLoRHS = Builder.CreateZExt(LoRHS, Ty, "lo.rhs.ext");
6514-
}
6515-
6516-
Value *Mul = Builder.CreateMul(ExtLoLHS, ExtLoRHS, "mul.overflow.no");
6507+
Value *Mul = Builder.CreateMul(LHS, RHS, "mul.overflow.no");
65176508

65186509
// In overflow.no BB: we are sure that the overflow flag is false.
65196510
// So, if we found this pattern:
@@ -6547,6 +6538,7 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
65476538
if (DetectNoOverflowBrBB) {
65486539
// BB overflow.no: jump directly to if.end BB
65496540
Builder.CreateBr(DetectNoOverflowBrBB);
6541+
65506542
// BB if.end:
65516543
Builder.SetInsertPoint(DetectNoOverflowBrBB,
65526544
DetectNoOverflowBrBB->getFirstInsertionPt());
@@ -6563,26 +6555,30 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
65636555
StructValNoOverflow, ConstantInt::getFalse(I->getContext()), {1});
65646556
// Replace all uses of I, only uses dominated by the if.end BB
65656557
I->replaceUsesOutsideBlock(StructValNoOverflow, I->getParent());
6558+
6559+
// Remove the original BB as it's divided into 'overflow.entry' and
6560+
// 'overflow' BBs.
6561+
BasicBlock *ToBeRemoveBB = I->getParent();
65666562
// BB overflow:
6567-
Builder.SetInsertPoint(OverflowBB,
6568-
I->getParent()->getTerminator()->getIterator());
6563+
OverflowBB->splice(OverflowBB->end(), ToBeRemoveBB);
65696564
// Extract the multiplication result to add it to the PHI node in the if.end
65706565
// BB
6566+
Builder.SetInsertPoint(OverflowBB, OverflowBB->end());
65716567
Value *IntrinsicMulRes = Builder.CreateExtractValue(I, {0}, "mul.extract");
6568+
cast<Instruction>(IntrinsicMulRes)->moveAfter(I);
65726569
NoOverflowPHI->addIncoming(IntrinsicMulRes, OverflowBB);
6570+
6571+
ToBeRemoveBB->eraseFromParent();
6572+
// Restore the original name of the overflow.entry BB:
6573+
OverflowEntryBB->setName(KeepBBName);
65736574
ModifiedDT = ModifyDT::ModifyBBDT;
65746575
return true;
65756576
}
65766577

65776578
// Otherwise, we need to create the 'overflow.res' BB to merge the results of
6578-
// the two paths.
6579+
// the two paths:
65796580
I->getParent()->setName("overflow.res");
65806581
BasicBlock *OverflowResBB = I->getParent();
6581-
OverflowBB = BasicBlock::Create(I->getContext(), "overflow", I->getFunction(),
6582-
OverflowResBB);
6583-
// Initially I->getParent() was the overflow BB, now it becomes the
6584-
// overflow.res BB. So we need to keep the old reference to the overflow BB.
6585-
OverflowResBB->replaceAllUsesWith(OverflowBB);
65866582

65876583
// BB overflow.no: jump to overflow.res BB
65886584
Builder.CreateBr(OverflowResBB);
@@ -6617,6 +6613,10 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
66176613
// Add The Extracted values to the PHINodes in the overflow.res block.
66186614
OverflowResPHI->addIncoming(MulOverflow, OverflowBB);
66196615
OverflowFlagPHI->addIncoming(OverflowFlag, OverflowBB);
6616+
6617+
// Restore the original name of the overflow.entry BB:
6618+
OverflowEntryBB->setName(KeepBBName);
6619+
66206620
ModifiedDT = ModifyDT::ModifyBBDT;
66216621
return true;
66226622
}

0 commit comments

Comments
 (0)