Skip to content

Commit 4390226

Browse files
committed
Fixed profitability mistake.
1 parent 435e3f9 commit 4390226

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,23 +2807,11 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
28072807
if (Instruction *Res = foldBinOpOfSelectAndCastOfSelectCondition(I))
28082808
return Res;
28092809

2810-
// (sub[ nsw][ nuw] (sext (add nsw (X, Y)), sext (X))) --> (sext (Y))
2811-
{
2812-
Value *Add0;
2813-
if (match(Op1, m_SExt(m_Value(X))) && match(Op0, m_SExt(m_Value(Add0))) &&
2814-
match(Add0, m_c_NSWAdd(m_Specific(X), m_Value(Y)))) {
2815-
// Non-constant Y requires new SExt.
2816-
unsigned NumOfNewInstrs = !isa<Constant>(Y) ? 1 : 0;
2817-
// Check if we can trade some of the old instructions for the new ones.
2818-
unsigned NumOfDeadInstrs = 0;
2819-
NumOfDeadInstrs += Op0->hasOneUse() ? 1 : 0;
2820-
NumOfDeadInstrs += Op1->hasOneUse() ? 1 : 0;
2821-
NumOfDeadInstrs += Add0->hasOneUse() ? 1 : 0;
2822-
if (NumOfDeadInstrs >= NumOfNewInstrs) {
2823-
Value *SExtY = Builder.CreateSExt(Y, I.getType());
2824-
return replaceInstUsesWith(I, SExtY);
2825-
}
2826-
}
2810+
// (sub (sext (add nsw (X, Y)), sext (X))) --> (sext (Y))
2811+
if (match(Op1, m_SExt(m_Value(X))) &&
2812+
match(Op0, m_SExt(m_c_NSWAdd(m_Specific(X), m_Value(Y))))) {
2813+
Value *SExtY = Builder.CreateSExt(Y, I.getType());
2814+
return replaceInstUsesWith(I, SExtY);
28272815
}
28282816

28292817
// (sub[ nsw] (sext (add nsw (X, Y)), sext (add nsw (X, Z)))) -->

0 commit comments

Comments
 (0)