@@ -5818,20 +5818,15 @@ static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
5818
5818
5819
5819
switch (Inst->getOpcode()) {
5820
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));
5821
+ Offsets.emplace_back(Instruction::Sub, Inst->getOperand(1));
5822
+ Offsets.emplace_back(Instruction::Sub, Inst->getOperand(0));
5825
5823
break;
5826
5824
case Instruction::Sub:
5827
- if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(1)))
5828
- Offsets.emplace_back(Instruction::Add, Inst->getOperand(1));
5825
+ Offsets.emplace_back(Instruction::Add, Inst->getOperand(1));
5829
5826
break;
5830
5827
case Instruction::Xor:
5831
- if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(1)))
5832
- Offsets.emplace_back(Instruction::Xor, Inst->getOperand(1));
5833
- if (isGuaranteedNotToBeUndefOrPoison(Inst->getOperand(0)))
5834
- Offsets.emplace_back(Instruction::Xor, Inst->getOperand(0));
5828
+ Offsets.emplace_back(Instruction::Xor, Inst->getOperand(1));
5829
+ Offsets.emplace_back(Instruction::Xor, Inst->getOperand(0));
5835
5830
break;
5836
5831
case Instruction::Select:
5837
5832
if (AllowRecursion) {
@@ -5892,7 +5887,11 @@ static Instruction *foldICmpEqualityWithOffset(ICmpInst &I,
5892
5887
// Avoid infinite loops by checking if RHS is an identity for the BinOp.
5893
5888
if (!Simplified || Simplified == V)
5894
5889
return nullptr;
5895
- return Simplified;
5890
+ // Reject constant expressions as they don't simplify things.
5891
+ if (isa<Constant>(Simplified) && !match(Simplified, m_ImmConstant()))
5892
+ return nullptr;
5893
+ // Check if the transformation introduces poison.
5894
+ return impliesPoison(RHS, V) ? Simplified : nullptr;
5896
5895
};
5897
5896
5898
5897
auto ApplyOffset = [&](Value *V, unsigned BinOpc,
0 commit comments