@@ -5818,20 +5818,15 @@ static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
58185818
58195819 switch (Inst->getOpcode ()) {
58205820 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 ));
58255823 break ;
58265824 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 ));
58295826 break ;
58305827 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 ));
58355830 break ;
58365831 case Instruction::Select:
58375832 if (AllowRecursion) {
@@ -5892,7 +5887,11 @@ static Instruction *foldICmpEqualityWithOffset(ICmpInst &I,
58925887 // Avoid infinite loops by checking if RHS is an identity for the BinOp.
58935888 if (!Simplified || Simplified == V)
58945889 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 ;
58965895 };
58975896
58985897 auto ApplyOffset = [&](Value *V, unsigned BinOpc,
0 commit comments