Skip to content

Commit 0ad2e48

Browse files
committed
[InstCombine] Address review comments.
1 parent 4900e37 commit 0ad2e48

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5813,19 +5813,20 @@ using OffsetOp = std::pair<Instruction::BinaryOps, Value *>;
58135813
static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
58145814
bool AllowRecursion) {
58155815
Instruction *Inst = dyn_cast<Instruction>(V);
5816-
if (!Inst)
5816+
if (!Inst || !Inst->hasOneUse())
58175817
return;
58185818

58195819
switch (Inst->getOpcode()) {
5820-
case Instruction::Add: {
5821-
Constant *C;
5822-
if (match(Inst->getOperand(1), m_ImmConstant(C)) &&
5823-
!C->containsUndefOrPoisonElement()) {
5824-
if (Constant *NegC = ConstantExpr::getNeg(C))
5825-
Offsets.emplace_back(Instruction::Add, NegC);
5826-
}
5820+
case Instruction::Add:
5821+
if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(1)))
5822+
Offsets.emplace_back(Instruction::Sub, Inst->getOperand(1));
5823+
if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(0)))
5824+
Offsets.emplace_back(Instruction::Sub, Inst->getOperand(0));
5825+
break;
5826+
case Instruction::Sub:
5827+
if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(1)))
5828+
Offsets.emplace_back(Instruction::Add, Inst->getOperand(1));
58275829
break;
5828-
}
58295830
case Instruction::Xor:
58305831
if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(1)))
58315832
Offsets.emplace_back(Instruction::Xor, Inst->getOperand(1));
@@ -5834,12 +5835,8 @@ static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
58345835
break;
58355836
case Instruction::Select:
58365837
if (AllowRecursion) {
5837-
Value *TrueV = Inst->getOperand(1);
5838-
if (TrueV->hasOneUse())
5839-
collectOffsetOp(TrueV, Offsets, /*AllowRecursion=*/false);
5840-
Value *FalseV = Inst->getOperand(2);
5841-
if (FalseV->hasOneUse())
5842-
collectOffsetOp(FalseV, Offsets, /*AllowRecursion=*/false);
5838+
collectOffsetOp(Inst->getOperand(1), Offsets, /*AllowRecursion=*/false);
5839+
collectOffsetOp(Inst->getOperand(2), Offsets, /*AllowRecursion=*/false);
58435840
}
58445841
break;
58455842
default:
@@ -5887,10 +5884,8 @@ static Instruction *foldICmpEqualityWithOffset(ICmpInst &I,
58875884
return nullptr;
58885885

58895886
SmallVector<OffsetOp, 4> OffsetOps;
5890-
if (Op0->hasOneUse())
5891-
collectOffsetOp(Op0, OffsetOps, /*AllowRecursion=*/true);
5892-
if (Op1->hasOneUse())
5893-
collectOffsetOp(Op1, OffsetOps, /*AllowRecursion=*/true);
5887+
collectOffsetOp(Op0, OffsetOps, /*AllowRecursion=*/true);
5888+
collectOffsetOp(Op1, OffsetOps, /*AllowRecursion=*/true);
58945889

58955890
auto ApplyOffsetImpl = [&](Value *V, unsigned BinOpc, Value *RHS) -> Value * {
58965891
Value *Simplified = simplifyBinOp(BinOpc, V, RHS, SQ);

0 commit comments

Comments
 (0)