Skip to content

Commit fee4823

Browse files
committed
Fixups
1 parent b8a977d commit fee4823

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,10 +1520,10 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
15201520
if (Instruction *R = combineAddSubWithShlAddSub(Builder, I))
15211521
return R;
15221522

1523-
if (Instruction *R = foldAddLike(I))
1524-
return R;
1525-
15261523
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
1524+
if (Instruction *R =
1525+
foldAddLike(LHS, RHS, I.hasNoSignedWrap(), I.hasNoUnsignedWrap()))
1526+
return R;
15271527
Type *Ty = I.getType();
15281528
if (Ty->isIntOrIntVectorTy(1))
15291529
return BinaryOperator::CreateXor(LHS, RHS);
@@ -2296,11 +2296,11 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
22962296
Instruction *R = nullptr;
22972297
if (W == Y)
22982298
R = BinaryOperator::CreateSub(X, Z);
2299-
if (W == Z)
2299+
else if (W == Z)
23002300
R = BinaryOperator::CreateSub(X, Y);
2301-
if (X == Y)
2301+
else if (X == Y)
23022302
R = BinaryOperator::CreateSub(W, Z);
2303-
if (X == Z)
2303+
else if (X == Z)
23042304
R = BinaryOperator::CreateSub(W, Y);
23052305
if (R) {
23062306
bool NSW = I.hasNoSignedWrap() &&

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3577,7 +3577,8 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
35773577
return R;
35783578

35793579
if (cast<PossiblyDisjointInst>(I).isDisjoint())
3580-
if (Instruction *R = foldAddLike(I))
3580+
if (Instruction *R = foldAddLike(I.getOperand(0), I.getOperand(1),
3581+
/*NSW=*/true, /*NUW=*/true))
35813582
return R;
35823583

35833584
Value *X, *Y;

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
586586
unsigned Depth = 0);
587587

588588
/// Common transforms for add / disjoint or
589-
Instruction *foldAddLike(BinaryOperator &I);
589+
Instruction *foldAddLike(Value *LHS, Value *RHS, bool NSW, bool NUW);
590590

591591
/// Canonicalize the position of binops relative to shufflevector.
592592
Instruction *foldVectorBinop(BinaryOperator &Inst);

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,26 +2008,24 @@ static bool shouldMergeGEPs(GEPOperator &GEP, GEPOperator &Src) {
20082008
return true;
20092009
}
20102010

2011-
Instruction *InstCombinerImpl::foldAddLike(BinaryOperator &I) {
2012-
Value *LHS = I.getOperand(0);
2013-
Value *RHS = I.getOperand(1);
2011+
Instruction *InstCombinerImpl::foldAddLike(Value *LHS, Value *RHS, bool NSW,
2012+
bool NUW) {
20142013
Value *A, *B, *C, *D;
20152014
if (match(LHS, m_Sub(m_Value(A), m_Value(B))) &&
20162015
match(RHS, m_Sub(m_Value(C), m_Value(D)))) {
20172016
Instruction *R = nullptr;
20182017
if (A == D)
20192018
R = BinaryOperator::CreateSub(C, B);
2020-
if (C == B)
2019+
else if (C == B)
20212020
R = BinaryOperator::CreateSub(A, D);
20222021
if (R) {
2023-
bool NSW = match(&I, m_NSWAddLike(m_Value(), m_Value())) &&
2024-
match(LHS, m_NSWSub(m_Value(), m_Value())) &&
2025-
match(RHS, m_NSWSub(m_Value(), m_Value()));
2026-
2027-
bool NUW = match(LHS, m_NUWSub(m_Value(), m_Value())) &&
2028-
match(RHS, m_NUWSub(m_Value(), m_Value()));
2029-
R->setHasNoSignedWrap(NSW);
2030-
R->setHasNoUnsignedWrap(NUW);
2022+
bool NSWOut = NSW && match(LHS, m_NSWSub(m_Value(), m_Value())) &&
2023+
match(RHS, m_NSWSub(m_Value(), m_Value()));
2024+
2025+
bool NUWOut = match(LHS, m_NUWSub(m_Value(), m_Value())) &&
2026+
match(RHS, m_NUWSub(m_Value(), m_Value()));
2027+
R->setHasNoSignedWrap(NSWOut);
2028+
R->setHasNoUnsignedWrap(NUWOut);
20312029
return R;
20322030
}
20332031
}

0 commit comments

Comments
 (0)