Skip to content

Commit 8607d5b

Browse files
committed
Discard the recent work of detecting the optimization pattern to
stop reprocessing, and instead use the current list of 'InsertedInsts' to keep track of processed instructions. The work of detecting the pattern needs to detect 4 patterns for cases when one/both of the parameters are constant. So the new solution is simpler and more secure.
1 parent 08c498c commit 8607d5b

File tree

2 files changed

+2
-162
lines changed

2 files changed

+2
-162
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,36 +6405,6 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
64056405
if (!TLI->shouldOptimizeMulOverflowIntrinsic())
64066406
return false;
64076407

6408-
// Check if we had already optimized this intrinsic by detecting the pattern of the changes we had made:
6409-
// Check if we are testing the high bits of the operands:
6410-
if (BasicBlock *BrBB = I->getParent()->getSinglePredecessor()) {
6411-
if (BranchInst *Br = dyn_cast<BranchInst>(BrBB->getTerminator()); Br && Br->isConditional()) {
6412-
if (IsSigned) {
6413-
// Check: cmp(or(xor(trunc(lshr(x))), xor(trunc(lshr(x)))))
6414-
if (match(Br->getCondition(),
6415-
m_Cmp(m_Or(m_Xor(m_Trunc(m_LShr(m_Specific(I->getOperand(0)), m_Value())), m_Value()),
6416-
m_Xor(m_Trunc(m_LShr(m_Specific(I->getOperand(1)), m_Value())), m_Value())),
6417-
m_Value()))) {
6418-
LLVM_DEBUG(dbgs() << "CGP: pattern detected - bail out\n");
6419-
// Pattern detected, bail out.
6420-
return false;
6421-
}
6422-
}
6423-
else
6424-
{
6425-
// Check: or(cmp(trunc(lshr(x)), cmp(trunc(lshr(y))))
6426-
if (match(Br->getCondition(),
6427-
m_Or(m_Cmp(m_Trunc(m_LShr(m_Specific(I->getOperand(0)), m_Value())), m_Value()),
6428-
m_Cmp(m_Trunc(m_LShr(m_Specific(I->getOperand(1)), m_Value())), m_Value())))) {
6429-
LLVM_DEBUG(dbgs() << "CGP: pattern detected - bail out\n");
6430-
// Pattern detected, bail out.
6431-
return false;
6432-
}
6433-
}
6434-
6435-
}
6436-
}
6437-
64386408
if (TLI->getTypeAction(
64396409
I->getContext(),
64406410
TLI->getValueType(*DL, I->getType()->getContainedType(0))) !=
@@ -6459,6 +6429,8 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
64596429
if (!I->getType()->isStructTy() || I->getType()->getStructNumElements() != 2)
64606430
return false;
64616431

6432+
// Keep track of the instruction to stop reoptimizing it again.
6433+
InsertedInsts.insert(I);
64626434
// ----------------------------
64636435

64646436
// For the simple case where IR just checks the overflow flag, new blocks

llvm/test/CodeGen/AArch64/mul_with_overflow.ll

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)